JasonBie

使用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();
}

 

 

posted on 2020-02-12 13:58  JasonBie  阅读(...)  评论(...编辑  收藏

My Links

Blog Stats