Bug 59732 - File Excel Created From Apache POI Can't Open by Ms Excel (file corrupt)
Summary: File Excel Created From Apache POI Can't Open by Ms Excel (file corrupt)
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-20 07:22 UTC by Stefano Toma
Modified: 2016-06-20 09:11 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefano Toma 2016-06-20 07:22:48 UTC
I don't know why the file I write using POI cant be opened by Ms Excel , but the file is still readable by POI. (cell value can be changed) 

Link file: http://www.corteconti.it/export/sites/portalecdc/_documenti/controllo/sez_autonomie/2016/schemi_di_bilancio_armonizzato_2015_ens_art_1_delibera_12_2016_sezaut_inpr.xls

here is the code

    String nomeFileArt1 = "schemi_di_bilancio_armonizzato_2015_ens_art_1_delibera_12_2016_sezaut_inpr.xls";
        NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(System.getProperty("java.io.tmpdir") + nomeFileArt1));
        HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), true);

        FileOutputStream stream = new FileOutputStream(System.getProperty("java.io.tmpdir") + "schemi_di_bilancio_armonizzato.xls");
        HSSFSheet sheet = wb.getSheet("Dati_Anagrafici");
        HSSFRow sheetrow = sheet.getRow(10);
        if (sheetrow == null) {
            sheetrow = sheet.createRow(10);
        }
        HSSFCell cell = sheetrow.getCell(0);
        if (cell == null) {
            cell = sheetrow.createCell(0);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        }
        cell.setCellValue("test");
        wb.write(stream);
        stream.close();
Comment 1 Javen O'Neal 2016-06-20 07:41:40 UTC
LibreOffice can read schemi_di_bilancio_armonizzato_2015_ens_art_1_delibera_12_2016_sezaut_inpr.xls and doesn't report any errors.

Does Excel give you any meaningful errors?

Also, could you try the following:

1. Without modifying the cells
> String nomeFileArt1 = "in.xls";
> NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(System.getProperty("java.io.tmpdir") + nomeFileArt1));
> HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), true);
> FileOutputStream stream = new FileOutputStream(System.getProperty("java.io.tmpdir") + "out.xls");
> wb.write(stream);
> stream.close();

2. Opening the workbook with preserveNodes=false (both with and without modifying the file)
> ...
> HSSFWorkbook wb = new HSSFWorkbook(fs.getRoot(), true);
> ...

3. Opening the workbook through more common methods
> WorkbookFactory.create(new File("in.xls"));
or
> WorkbookFactory.create(new FileInputStream("in.xls"));
Comment 2 Stefano Toma 2016-06-20 07:51:34 UTC
I've tried all the solutions , but without success. to open the file I used ms excel 2010.
The error message is:
Excel found unreadable content
Comment 3 Javen O'Neal 2016-06-20 08:49:38 UTC
So what you're saying is that if you start with a non-corrupt workbook and run it through the following code, you get a corrupt (according to Excel) workbook?

> @Test
> public void test59732() {
>     File f = new File("in.xls");
>     Workbook wb = WorkbookFactory.create(f);
>     OutputStream fos = new FileOutputStream("out.xls");
>     wb.write(fos);
>     fos.close();
>     wb.close();
> }

Does this happen using other workbooks?
What version of POI are you using?
Does Excel 2010 give any more detail on the error?
Comment 4 Stefano Toma 2016-06-20 09:11:42 UTC
So what you're saying is that if you start with a non-corrupt workbook and run it through the following code, you get a corrupt (according to Excel) workbook?
Yes

Does this happen using other workbooks?
With other workbooks it works

What version of POI are you using?
3.10 Final and 3.14

Does Excel 2010 give any more detail on the error?
No