Problem to read formulas using Apache POI

Asked

Viewed 209 times

2

I’m creating a method to hide the elements that are zeroed out from an excel file, but the problem that it can’t catch the values when the column is a formula. How can I get these values?

My code:

private static ByteArrayOutputStream ocultarZerados(ByteArrayOutputStream arquivo) throws Exception
{
    InputStream arquivoExcel = new ByteArrayInputStream(arquivo.toByteArray());
    XSSFWorkbook wb = new XSSFWorkbook(arquivoExcel);


    XSSFSheet s = (XSSFSheet) wb.getSheetAt(1);

    for (Row linha : s)
    {
        System.out.println("===================");

        for (Cell coluna : linha)
        {
            if(coluna.getCellType() == 1)
            {
                System.out.print(coluna.getStringCellValue() + "|");
            }
            else {
                System.out.print(coluna.getNumericCellValue() + "|");
            }
        }

        System.out.println("===================");
    }

    wb.write(arquivo);
    wb.close();

    return arquivo;
}
  • I ran the test using poi 3.17 and it worked normally. In case you haven’t been able to solve the problem, if you can,.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.