string filepath = System.AppDomain.CurrentDomain.BaseDirectory+"exmp.xlsx";
FileStream fileStream = new FileStream(filepath,FileMode.Open,FileAccess.Read);
XSSFWorkbook wb = new XSSFWorkbook(fileStream);
ISheet sheet = wb.GetSheet("Sheet1");
IRow row = sheet.GetRow(0);
ICell cell = row.GetCell(0);
cell.SetCellValue("helloworld");
using (FileStream filesm = File.OpenWrite("exmp.xlsx"))
{
wb.Write(filesm);
}
就是简单的往excel中传输一个值过去然后保存,可是打开excel就提示文件损坏:
点“是”之后,提示:
麻烦各位大佬帮忙看下这段代码有什么问题,就这么几句怎么也想不到问题在哪。
看看是不是你的excel版本过高,npoi不支持。
刚用你的代码跑了一下,并没有出现你的说的情况,但是helloworld并没有写入成功。你现在的bug目测是因为你的excel版本问题,卸载了重新装下。我的是excel2007