Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Created Unassigned: xlsx file is corrupted when modified by XSSF [12616]

$
0
0
It seems that XSSF can only work with the xlsx file created by it self.
When I modify and save an xlsx file created by Excel 2010, it will be failed to be opened in Excel 2010. This error dialog will display:
```
Excel found unreadable content in 'test.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
```
.
See my code below:
```
/*
IWorkbook workbook1 = new XSSFWorkbook();
workbook1.CreateSheet("Sheet1");
workbook1.CreateSheet("Sheet2");
workbook1.CreateSheet("Sheet3");
FileStream sw1 = new FileStream("test_by_xssf.xlsx", FileMode.Create);
workbook1.Write(sw1);
sw1.Close();
*/

// no error when use the test_by_xssf.xlsx created by the code above
//FileStream so = new FileStream("test_by_xssf.xlsx", FileMode.Open);

// error occurs when use the test_by_excel.xlsx created by Excel 2010
FileStream so = new FileStream("test_by_excel.xlsx", FileMode.Open);

IWorkbook workbook = new XSSFWorkbook(so);
workbook.CreateSheet("SheetAdd");
FileStream sw2 = new FileStream("test.xlsx", FileMode.Create);
workbook.Write(sw2);
so.Close();
sw2.Close();
```
.
Attached is my xlsx file create by excel 2010.

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>