使用C#的NPOI操作Excel表格后,发现表格再不能打开了,原因是扩展名不匹配,为什么
using (FileStream file = new FileStream(strExcelPath, FileMode.Open, FileAccess.Read)) { workbook = new XSSFWorkbook(file); file.Close(); file.Dispose(); }
已经解决了,在代码之前要加一段
using (FileStream fileMuban = new FileStream(path1, FileMode.Open, FileAccess.Read))
{
XSSFworkbook = new XSSFWorkbook(fileMuban);
}
using (FileStream fileTarget = new FileStream(path1, FileMode.Create, FileAccess.Write))
{
XSSFworkbook.Write(fileTarget);
}
操作以后的扩展名是啥?
我是这样操作的
using (FileStream file = new FileStream(path1, FileMode.Open, FileAccess.Read))
{
XSSFworkbook = new XSSFWorkbook(file);
var sheet = XSSFworkbook.GetSheetAt(0);
//int columnCount = mName2Infos[infos1].minfo.Count;
for(int i=0;i<5;i++)
{
IRow row=sheet.GetRow(i);
row.GetCell(2).SetCellValue(model[model_head[model_head_Count-1]].list1[i]);
}
}
using (FileStream filess = File.OpenWrite(path1))
{
XSSFworkbook.Write(filess);
}
@lazycat_1: 你电脑上装的是office的什么版本?
@顾晓北: 在没操作之前是可以打开的,操作之后就打不开了,装的2010的