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.
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
We have a excel document that contains a ton of Hyperlinks to other Excel Documents & File Paths all located on our network. All of a sudden the Hyperlinks to the Excel Documents have broken, Excel will state the error below;
Some files can contain viruses or otherwise be harmful to your computer. It is important to be certain that this file is from a trustworthy source.
Would you like to open this file? OK/Cancel
We click OK and nothing will happen. Opening file paths is still working fine and I've created another Excel document which has links to a PDF, a File Path, a Word Doc & an Excel Doc. Still only the Excel that isn't working.
I have followed several articles online that suggest how to disable the warning message,below is a well detailed article for 2007/2010 but we had tried to adapt it for 2013/6. Nothing I have tried is working, does anyone on Stack have any suggestions?
https://support.microsoft.com/en-gb/help/925757/how-to-enable-or-disable-hyperlink-warning-messages-in-2007-office-pro
We are using Office 2013/6 Standard/Professional.
Any help would be greatly appreciated!!
Many thanks,
Sean
This happens when you copy the excel file to different location:
You can do test: place hyperlink into 1 cell save it, and then copy the file to another location: you can see that hyperlink of your copied excel file would not work.
However when you choose the same file to "Save As": the hyperlink of the saved file in different location will work.
For excel internal hyperlinks (hyperlinks to other worksheet cells) similar thing happens when you rename the file: hyperlinks won't work, but they will work if you choose to "Save As".
This means, the solution to this problem would be: copy the excel file to it's original location and name it with the original name (when hyperlinks were working). In this case hyperlinks will work. Then if you need to move or rename the file: open the file from original location and select "Save AS" anywhere you would like to save, in this case hyperlinks of your saved file would work.
Conclusion: relative references to the Excel file in hyperlinks are not automatically updated when externally file is moved or renamed.
So we managed to find out what was the cause of this problem.
Microsoft are currently working on fixing this as stated in the article below, but as a quick fix you simply need to remove Windows Update KB4011051.
https://support.office.com/en-gb/article/Hyperlinks-to-another-Excel-workbook-no-longer-work-after-updating-to-the-August-1-2017-update-KB-4011051-dfe0aa5c-a2ba-41b8-923a-fe0e4556f936
Thanks for the assistance,
Sean
I use Display tag in Struts 1.3 to export a table to .xls file.I can export this without any problem and I can open this file with a text editor and view or edit.
<display:setProperty name="export.excel.filename" value="Export.xls"/>
Then created .xls file in Excel 2003 and try to edit it with text editor, but it's binary file.
The file size created with Excel is much bigger comparing to exported file.
Furthermore, When I try to open the exported .xls file in Excel 2013 it gives following popup,
"The file format and extension of 'Export.xls' don't match.
The file could be corrupted or unsafe.
Unless you trust its source ,don't open it.
Do you want to open it anyway ? (Yes/No/Help)"
What is the reason for this?
I found the reason behind this.The exported Excel(.xls) from displaytag is text-based excel and not a POI-based excel.But Excel application creates binary .xls file.
I'm running into a strange issue when trying to load excel spreadsheets into my database through SSIS (2012).
I'm getting the spreadsheets (which are xlsx files) via email, and then I manually save them to my local drive (C:\temp). When I try to use the excel file as a source in SSIS, I am not able to pick any excel sheets in the book.
The file is not corrupted, not open on my machine, and not password protected. It is, however, opening in Protected View. So I go into Excel and turned off all the Protected View options, but no cigar. The only way I am able to use the file as an excel source in SSIS is by opening it, and saving over it.
Does anyone have a similar experience? Other than opening and saving all of the files manually, is there a better solution?
It's a known issue with xml based excel (xlsx). If you can save them as xls, that will solve the problem. If for some reason that's not possible you may need to use OLE source to read them.
[SOLVED (see answer below)] I am using SpreadsheetWorker API to make working with Open XML SDK 2.0 easier. I have an excel spreadsheet that I use as a template when I generate new excel spreadsheets through SpreadsheetWorker. I am getting a "found unreadable content" error when I open my generated files, and excel will correct the problems with the file if you allow it. This is not suitable for production.
While adding hyperlinks to excel cell, try to avoid dynamic URL to screenTip attribute. Excel cell takes only 256 charecter long for tooltip. The repaired excel file chops off the characters after this limit.
For Spreadsheet gear,
worksheet.Hyperlinks.Add(worksheet.Cells[startRow, startColumn], href, null, "Click here to see details","textToDisplay");
Solved my own question: In my excel spreadsheet that I used as a template, I had some blank cells with 'Hyperlink' styles applied to them. Setting the style of these cells to 'Normal' fixed the problem, and I no longer get the "unreadable content" error when I open generated spreadsheets for the first time.