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

Commented Unassigned: Reg. Error while Saving Excel using NPOI 2.0Beta [12558]

$
0
0
FileStream file = new FileStream(@"C:\test.xls", FileMode.Open, FileAccess.ReadWrite);

HSSFWorkbook wrkBook = new HSSFWorkbook(file);
ISheet ws = wrkBook.GetSheetAt(1);

IRow r = ws.GetRow(20);
ICell c = r.GetCell(3);

c.SetCellValue("ABC");

wrkBook.Write(file);

file.Close();

Here I am getting the error "Cannot access closed file" at line " wrkBook.Write(file);" .

Can anyone please help me ?
Comments: ** Comment from web user: fz0000 **

Try the code below:
```
FileStream file = new FileStream(@"C:\test.xls", FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook wrkBook = new HSSFWorkbook(file);
file.Close();
ISheet ws = wrkBook.GetSheetAt(1);
IRow r = ws.GetRow(20);
ICell c = r.GetCell(3);
c.SetCellValue("ABC");

FileStream file_again = new FileStream(@"C:\test.xls", FileMode.Open, FileAccess.ReadWrite);
wrkBook.Write(file_again);
file.Close();
```


Viewing all articles
Browse latest Browse all 1621

Trending Articles



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