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

Commented 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.
Comments: ** Comment from web user: jitendrasingh **

Hi Team,

I experianced the same problem while working on NPOI 2.1.3 version. Excel is getting corrupt while writing excel with program. Can you please look at below post of mine and help on this.

https://npoi.codeplex.com/discussions/631718

Thanks in advance
Jitendra Singh


Viewing all articles
Browse latest Browse all 1621

Trending Articles



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