从输出表中获取旧值 - Excel POI

时间:2017-08-05 07:17:41

标签: java apache-poi

我有一个excel工作簿,其中包含(InputOuputCalc),之前所有工作表都填充了输入工作表有许多输入单元格,我填写了输入单元格没有问题,但是当我转到输出表格以获得新结果时,我得到旧的单元格值,每个输出单元格都有一个公式ex:

单元格B2价值=Calc!F8

这是我试过的:

/**
     * ********************************** Insert values into the Excel ********************************************
     */

    File excel = stream2file(Core.getFileDocumentContent(getContext(), ExcelFileParameter1));
    FileInputStream fis = new FileInputStream(excel);

    XSSFWorkbook hssfWorkbook = new XSSFWorkbook(fis);
    XSSFSheet inputSheet = hssfWorkbook.getSheet("Input");

    XSSFRow inputSheetRow;
    XSSFCell inputCell;

    for (int i = 1; i <= inputSheet.getPhysicalNumberOfRows() - 1; i++) {

        inputSheetRow = inputSheet.getRow(i);
        inputCell = inputSheetRow.getCell(1);

        switch (i) {
        case 1:
            String date = this.ExcelInputParameter1.getDOB().toString();
            SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss z yy");
            Date currentdate = sdf.parse(date);
            SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy");
            inputCell.setCellValue(sdf2.format(currentdate));
            break;
        case 2:
            inputCell.setCellValue(this.CountryParameter1.getDescription());
            break;

        }
    }

    fis.close();
    FileOutputStream fos = new FileOutputStream(excel);
    hssfWorkbook.write(fos);
    fos.close();


    /**
     * ********************************** Get The output from the Excel ********************************************
     */

    fis = new FileInputStream(excel);
    hssfWorkbook = new XSSFWorkbook(fis);
    XSSFSheet outputSheet = hssfWorkbook.getSheet("Output");

    XSSFRow outputSheetRow;
    XSSFCell outputCell;

    for (int i = 1; i <= outputSheet.getPhysicalNumberOfRows() - 1; i++) {
        outputSheetRow = outputSheet.getRow(i);
        outputCell = outputSheetRow.getCell(1);

        switch (i) {

        case 1:
            this.ExcelOutputParameter1.setCover_1((int) outputCell.getNumericCellValue());
            break;
        case 2:

            this.ExcelOutputParameter1.setCover_2((int) outputCell.getNumericCellValue());
            break;
        }

    }
    fis.close();

    return this.ExcelOutputParameter1;
    }

还尝试评估细胞配方:

        outputSheetRow = outputSheet.getRow(i);
        outputCell = outputSheetRow.getCell(1);

        CellValue cellValue = evaluator.evaluate(outputCell);

但是CellValue = [#VALUE!],我尝试使用MS Excel打开工作簿,并且输出正确。

0 个答案:

没有答案