本人的代码如下:
//往excel的某个单元格填充内容 public void FillExcelCell(string excelPath, int rowIndex, int columnIndex, string content) { try { //读取excel try { FileStream stream = new FileStream(excelPath, FileMode.Open, FileAccess.ReadWrite); HSSFWorkbook workBook = new HSSFWorkbook(stream); ISheet sheet = workBook.GetSheetAt(0); if (sheet.GetRow(rowIndex) == null) { sheet.CreateRow(rowIndex); } if (sheet.GetRow(rowIndex).GetCell(columnIndex) == null) { sheet.GetRow(rowIndex).CreateCell(columnIndex); } sheet.GetRow(rowIndex).GetCell(columnIndex).SetCellValue("ssss"); workBook.Write(stream); stream.Close(); } catch (Exception ex) { var a = ex.Message; } } catch (Exception ex) { Console.Write(ex.Message); } }
不知道为什么总会有这两个异常的产生:
Handle = “stream.Handle”引发了“System.ObjectDisposedException”类型的异常
IsReadOnly = “workBook.IsReadOnly”引发了“System.NotImplementedException”类型的异常
问一下各路大牛,本人是哪里写错了
解决方案
20
把
Handle = “stream.Handle”
的代码放出来看,你到底写哪里了
Handle = “stream.Handle”
的代码放出来看,你到底写哪里了