spreadsheet
spreadsheet copied to clipboard
Spreadsheet.write(OutpuStream out) produces corrupted XLSX files.
Originally by mbranicky
We have a use case when we are loading Excel data from XLSX file right into the Spreadsheet component. Even very large or complex sheets with lot's of styling are loaded correctly. However when we write this data back into the new XLSX file and the excel data contains some formatting (bold font for instance), the outcome file gets corrupted and Excel refuses to open it and offers a repair of such a corrupted file.
To read from excel file:
#!java
this.spreadsheet.read(excelInputResource.getInputStream());
To write into excel file:
#!java
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
this.spreadsheet.write(baos);
String newResourceIcrPath = xlsFilePath + "/" + xlsFileName + "_" + new Date().getTime() + xlsFileSuffix;
// 'excelOutputResource' is our internal resource
IcrResource excelOutputResource = resourceCacheProvider.get().createIcrResource(newResourceIcrPath);
// writes input stream into the file on file system
excelOutputResource.store(new ByteArrayInputStream(baos.toByteArray()));
IOUtils.closeQuietly(baos);
I've also tried to use method Spreadsheet.write(String fileName), but the outcome file is still corrupted.
Please see attached original empty file, corrupted file (produced when any formatting is used in excel data) and repaired file. I've also attached an Excel log file, produced by repair process.
VAADIN Core 7.6.8.
VAADIN Spreadsheet 1.2.1
Microsoft Excel for MAC version 15.25
Imported from https://dev.vaadin.com/ issue #20180
Originally by mbranicky
Attachment added: empty_corrupted.xlsx (13.3 KiB)
Created but corrupted outcome file
Originally by @Ansku
https://bz.apache.org/bugzilla/show_bug.cgi?id=60184