My Scenario is like i want to download Excel from our Application, which contains n number of rows. After downloading the Excel i want to update datas into the excel using poi jar. The problem here is when i manually creating the excel and try to update the excel cellvalues at that time it is working fine, But after downloading the Excel i am trying make changes at the time its not updating the values.. No error message in console..
I think it will be in read only mode.. How to solve this problem?
Related
TL;DR: Excel Workbook generated by Docx4J always says corrupted but I can't determine what Excel doesn't like about the underlying XML, let alone how to fix it.
My use case is as follows:
I am trying to produce an excel workbook with charts and graphs automatically on a regular basis. Only the raw data will change but everything else will dynamically update as the raw data is changed.
So I built an excel workbook which has a number of charts and graphs being generated by a sheet of raw data. I am using it as a template. All values of the raw data are numeric. The intent was to use Docx4J to read this 'template' and to populate the raw data sheet, then save it as a new file whereupon opening will initiate the recalculation and the charts and graphs will update. Since I am new to Docx4j, I basically decided to do baby steps by first seeing if I could open and read the contents of the cells; which I could. So far so good. I also could change the values of the cells but I could only verify this programatically by writing out to the console the location and value before a change, then the location and value after the change (ex. A1=45 followed by A1=55).
My problem starts when I try to open the resulting file. It generates, looks to be about the right size but Excel claims it is corrupted. It does try to recover what it can, but ultimately fails and the workbook won't even open. For troubleshooting, I opened up the generated xlsx and confirmed all the various XML files that make up an xlsx file were present and readable so I am concluding either something is missing or some part of the XML coming out the other side is not what Excel wants. Further troubleshooting involved creating an empty workbook (no data, 1 sheet) as my 'template', opening it and then saving it back to the file system with a different name and simply trying to see if I could open it in Excel but no dice. This has me ruling out anything to do with my attempts to write or add data to the sheet.
Relevant Environment Information:
'template' workbook is being generated on a Windows 10 64bit machine
My docx4j code is executing on a Debian 10 Linux machine running OpenJDK 11.0.4
My version of Excel both to create the 'template' and open the copy is Excel for Office365
I am running Docx4J v11.1.3 but I also tried with v8.1.5(both cases I had to use the Reference Implementation of JAXB to get around a marshalling error when trying to save)
I did see another post on Stackoverflow here about an issue related to fonts in Linux environments so I made sure to install the MS TT Corefonts but it didn't help my problem.
I ran the entire unzipped directory through BeyondCompare and there are some differences but I don't know which are just artifacts of the two different OS' or even which differences matter. Mostly they are:
small differences in file size
boolean values showing as "1", "yes", or "true" but not the same way for both files
namespaces and attributes in one file but not the other
Sheet1 from my blank workbook, before and after
All ideas are welcome.
Please try the just-released docx4j 8.1.6, which fixes handling of xlsx files created by recent releases of Excel. This was https://github.com/plutext/docx4j/issues/389
When creating an Excel using the example CreateSimpleSpreadsheet.java.
The created spreadsheet shows correctly the sample data in MacOS Excel (Ver 15.30 - 170107)
but when opening in MacOS using Numbers (ver 3.6.2 - 2577) the sheet is empty.
However, when opening in Excel under MacOS and then saving the sheet new and opening the new file using Numbers, the sheet is correctly displayed.
What is the cause for this ?
I need the created xlsx file opens correctly in Numbers under MacOS also
Saving the XLSX in Excel 2010 adds a reference attribute to each cell, eg #r="A1". Try adding that to the first cell, and B1 to the second.
Excel also makes other changes which don't matter, including #r=1 on the row, and using shared strings (as opposed to inline strings). An easy way to see them is to use the Open XML SDK 2.0 Productivity Tool's compare files feature. But that's for Windows...
UPDATE NEXT MORNING
Adding the reference attribute to each cell, eg #r="A1", is all that's required for iCloud Numbers (as of time of writing) to display cell contents.
https://github.com/plutext/docx4j/commit/05c368caca7dd404f8d39f83346a7980b6cfdcf1 adds those.
I'm processing xlsx files in PHP. When I create xlsx file using openoffice with just one filled cell, the spreadsheet already has 65536 rows itself. It looks like openoffice stores all cells even if they are empty. Is there any solution I can save only as many rows/columns as they are filled? Because every library for parsing xlsx produces then wrong number of rows so I'm not able to process it correctly. Good solution would be to achieve it directly inside openoffice, or use some external tool/script (*nix based) to clean up such xlsx file if possible.
Here is one solution:
Use OpenTBS to open the XLSX and save it with or without modifications.
OpenTBS is a pure PHP tools whose purpose is to merge data with LibreOffice and Ms Office documents using the technique of templates.
Since its version 1.9.0, OpenTBS can handle with XLSX workbooks made with LibreOffice. Such XLSX workbooks may have an extra row definition which contains a repetition attribute that extends it upon the maximum limit of row number. OpenTBS simply reduce this extra extended row into a single row.
OpenTBS download page
OpenTBS demo
OpenTBS doc
After generating the excel sheet using Java POI and opening the newly created Excel file I get a message box saying
Excel found unreadable content in "abc.xlxs" .Do you want to recover the contents of this workbook?If you trust the source of this workbook, click 'yes'.
And when I click 'yes' I get some message like this
Excel was able to open the file by repairing or removing the unreadable content
After that I can view the contents in the sheet. How can I remove all these kind of messages while opening it?
You should check if you use the right api:
For .xls files you must use HSSF.
For .xlsx files you must use XSSF or higher version api.
Check if you write your excel file correct.
And for the right answer, provide some code, please.
our Java EE applications writes large (>3000 rows, >300 columns) Excel files using Apache POI. We have implemented the customer's requirement that many (>500) of the cells in the written file have a partial text formatting, i.e. the text in one cell is partially red and bold, and partially black.
Apache POI does not complain when writing the files, and they can be opened, BUT Excel 97 misdisplays them: parts of the cells have the wrong font size, and cells with multiple font colors cannot be changed (altering the font size on them does not work).
Also, Excel 2010 complains that the file is insecure (when downloaded from the server), and both Excel 97 and Excel 2010 crash on the exported files frequently.
The previous version of the application used JExcelApi and did not write multiformatted text cells. The files generated by the server using the previos (JExcelApi-powered) version of the application do display normally in Office2010, without the security warning.
Did anyone come across these issues and if so, how can I fix them?
Also, did anyone figure out why setting AutoFilters fails to show up in Office 2010 in the specified, yet shows up in Excel 97 correctly (so it sometimes crashes or works just until one AutoFilter is selected?).
Finally, I have tried to roundtrip an Excel export of the older version of the application, and found that Apache POI reduces the file size by >35%, while breaking the file's contents - although no changes are applied (just reading the file into a HSSF Workbook and re-writing it into a ByteArrayOutputStream. Did anyone figure out how to prevent POI from altering the written file?
Thanks,
Michael
There's a lot of questions here, but it sounds like POI is outputting records that 97 is misinterpreting. There are significant differences between a 97' .xls and a 2003 .xls. The dialog behaving strangely is often a symptom of a malformed record. Excel 2010 has a binary file validator that it runs internally on any of the binary file format files (BIFF). It will pick up on any records that aren't to the BIFF specifications.
I'm not sure what's going on with the AutoFilters or the altering behavior.
If you're having a lot of trouble with POI, you may wish to check out OfficeWriter which does a pretty good job with 2010 validation and styles in general.
DISCLAIMER: I'm one of the engineers who wrote the latest version.
The root cause of our problem was traced to conditional formatting introduced in the excel template files. This resulted in the output file having conditional formatting.
We got rid of the conditional formatting and all is well now !
The problem manifests very severely when the users try to access the files over network.
Conditional formatting can be removed from excel.
Do ensure to remove the conditional formatting from all sheets / styles as well.