簡體   English   中英

如何在 apache poi 中使用 2 行的單元格引用

[英]how to use cellreferences with 2 rows with apache poi

我需要進行這些驗證,但是當我嘗試從 b4 行獲取值時,出現錯誤,因為 Row 參數從 cellReferenceC3“第 3 行”獲取行,但我需要從第 3 行和第 4 行、c3 和 b4

Row row = sheet.getRow(cellReferenceC3.getRow());

private boolean validaLinha(InputStream arquivoCancelamento) 拋出 IOException{

        XSSFWorkbook wb = new XSSFWorkbook(arquivoCancelamento);
        wb.setForceFormulaRecalculation(true);
        Sheet sheet = wb.getSheetAt(0);
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        String celulaB3 = "N\u00FAmero do Cart\u00E3o ";
        String celulaC3 = "N\u00FAmero Pedido";
        String celulaD3 = "Motivo de Cancelamento";
        String celulaE3 = "Observa\u00E7\u00E3o";
        String celulaB4 = "";
        boolean val = false;

        CellReference cellReferenceB3 = new CellReference("B3");
        CellReference cellReferenceC3 = new CellReference("C3");
        CellReference cellReferenceD3 = new CellReference("D3");
        CellReference cellReferenceE3 = new CellReference("E3");
        CellReference cellReferenceB4 = new CellReference("B4");

        Row row = sheet.getRow(cellReferenceC3.getRow());


        Cell cellB3 = row.getCell(cellReferenceB3.getCol());
        Cell cellC3 = row.getCell(cellReferenceC3.getCol());
        Cell cellD3 = row.getCell(cellReferenceD3.getCol());
        Cell cellE3 = row.getCell(cellReferenceE3.getCol());
        Cell cellB4 = row.getCell(cellReferenceB4.getCol());


        if ((cellReferenceB3!=null && celulaB3.equals(cellB3.getStringCellValue() ))
                &&  (cellReferenceC3!=null && celulaC3.equals(cellC3.getStringCellValue() ))
                && (cellReferenceD3!=null && celulaD3.equals(cellD3.getStringCellValue() ))
                && (cellReferenceE3!=null && celulaE3.equals(cellE3.getStringCellValue() ))
                && (cellReferenceB4!=null)

為什么不這樣,即有兩個引用,一個指向第 3 行,一個指向第 4 行?

        XSSFWorkbook wb = new XSSFWorkbook(arquivoCancelamento);
        wb.setForceFormulaRecalculation(true);
        Sheet sheet = wb.getSheetAt(0);
        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
        String celulaB3 = "N\u00FAmero do Cart\u00E3o ";
        String celulaC3 = "N\u00FAmero Pedido";
        String celulaD3 = "Motivo de Cancelamento";
        String celulaE3 = "Observa\u00E7\u00E3o";
        String celulaB4 = "";
        boolean val = false;

        CellReference cellReferenceB3 = new CellReference("B3");
        CellReference cellReferenceC3 = new CellReference("C3");
        CellReference cellReferenceD3 = new CellReference("D3");
        CellReference cellReferenceE3 = new CellReference("E3");
        CellReference cellReferenceB4 = new CellReference("B4");

        Row row3 = sheet.getRow(cellReferenceC3.getRow());

        Cell cellB3 = row3.getCell(cellReferenceB3.getCol());
        Cell cellC3 = row3.getCell(cellReferenceC3.getCol());
        Cell cellD3 = row3.getCell(cellReferenceD3.getCol());
        Cell cellE3 = row3.getCell(cellReferenceE3.getCol());

        Row row4 = sheet.getRow(cellReferenceB4.getRow());
        Cell cellB4 = row4.getCell(cellReferenceB4.getCol());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM