Bug 68974 - Unable to edit cell type on excel file that was generated via Apache Poi API
Summary: Unable to edit cell type on excel file that was generated via Apache Poi API
Status: RESOLVED DUPLICATE of bug 68985
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-03 22:27 UTC by J English
Modified: 2024-05-08 20:32 UTC (History)
0 users



Attachments
Generic excel file that shows the cell type issue (17.39 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2024-05-03 22:27 UTC, J English
Details
zip file that contains class, test class, csv file, excel template, and output files (40.96 KB, application/x-zip-compressed)
2024-05-06 21:32 UTC, J English
Details
zip file contains a simple test class and an excel template (11.99 KB, application/x-zip-compressed)
2024-05-07 00:26 UTC, J English
Details

Note You need to log in before you can comment on or make changes to this bug.
Description J English 2024-05-03 22:27:54 UTC
Created attachment 39695 [details]
Generic excel file that shows the cell type issue

To give a quick synopsis, I'm using Apache POI API to generate an excel file. I first collect and print all the data needed into a csv file. I then import the csv file into an excel file using an excel template. When the excel file is finished generating, everything looks as expected. However, when I attempt to change the cell type for any cell, the change never takes effect. I think it might the result of importing all data as String values onto the excel file, but I'm not really sure.

I need the ability to update the cell type for specific cells so that our clients can add their custom formulas to the excel after it's been generated. For example, if A1 is a numeric cell with a value = 123.45 and I add the formula to an empty cell '=SUM(A1)', the result the formula return '0'. I've even tried changing the cell type of A1 to Numeric, but the formula still returns 0. Can someone please confirm if these is a bug, or if there is anything I can do to allow the manually cell type edits to take effect after the excel file has been generated?

I've attached a generic xlsx file that shows the issue that I am referring to.
I'm trying to run SUMIF formula to subtotal amounts that have a certain value in a description column.

Thank you.
Comment 1 J English 2024-05-03 22:29:48 UTC
I am current using the 4.1.2 version of Apache POI
Comment 2 PJ Fanning 2024-05-03 23:07:29 UTC
The file is useless without the code that demos what you are doing.
Comment 3 PJ Fanning 2024-05-03 23:11:18 UTC
If you want Excel to calculate the formulas when you open the workbook, you need to call.

workbook.setForceFormulaRecalculation(true);

POI has some basic support for calculating formula results but a lot of Excel functions are not supported or only partially supported. I would strongly recommend just using setForceFormulaRecalculation(true).

https://poi.apache.org/components/spreadsheet/eval.html
Comment 4 J English 2024-05-06 21:32:47 UTC
Created attachment 39697 [details]
zip file that contains class, test class, csv file, excel template, and output files

Thank you for your help. I tried adding the recommended line of code (below) to my class, but it unfortunately it did not resolve my issue.

workbook.setForceFormulaRecalculation(true);

I've attached a zip file that contains a version of my class that can be used to reproduce the issue that I am seeing. I've also included a csv file, an excel template, output files, and a test class to run a quick test of my code. Please let me know if you need anything else.

Thank you.
Comment 5 J English 2024-05-06 21:44:03 UTC
Sorry, please use this version of the test class. This version has the correct file  names for the csv file, excel template file, and output file.

Thank you



import java.io.File;

public class TestExcelWriter
{
    public static void main(String[] args) throws Exception
    {
        File outPutFile = new File("outputFile.xlsx");
        String templateFilePath = "template.xlsx";
        File csvFile = new File("inputFile.csv");
        ExcelWriter excelWriter = new ExcelWriter();
        excelWriter.generateExcelFile(outPutFile, templateFilePath, csvFile);
    }
}
Comment 6 PJ Fanning 2024-05-06 21:47:54 UTC
I am not going to look any further at that sample. It is far too complicated.
Comment 7 J English 2024-05-06 22:27:35 UTC
OK got it. No worries. I'll try uploading much simpler version of the code. I'll keep you posted.
Comment 8 J English 2024-05-07 00:26:44 UTC
Created attachment 39698 [details]
zip file contains a simple test class and an excel template

Hi PJ,

Hopefully this is a lot simpler than the previous version. Simply run the test class. The excel template path should be relative.

The excel template contains 1 row and 1 cell as the source row/cell that will be used for all rows.

After running the test class, if you manually add '=SUM(A1:A6)' to any cell to get the sum of all modified cells, you will notice that the formula is not calculating correctly.

Please let me know if you need anything else.

Thank you
Comment 9 PJ Fanning 2024-05-08 20:32:15 UTC

*** This bug has been marked as a duplicate of bug 68985 ***