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();
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"));
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
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?
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