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 **
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();
```