使用NPOI编辑Excel
使用NPOI编辑Excel,如果不能保存,需要存到一个新的文件名:
XSSFWorkbook wb1 = null; using (var file = new FileStream("D:\\banding.xlsx", FileMode.Open, FileAccess.ReadWrite)) { wb1 = new XSSFWorkbook(file); } wb1.GetSheetAt(0).GetRow(0).GetCell(0).SetCellValue("Sample"); using (var file2 = new FileStream("D:\\banding2.xlsx", FileMode.Create, FileAccess.ReadWrite)) { wb1.Write(file2); file2.Close(); }