运行代码:
class Program
{
static void Main(string[] args)
{
FileStream file = new FileStream("test1.xlsx", FileMode.Open);//读入excel模板
IWorkbook workbook = new XSSFWorkbook(file);
workbook.RemoveSheetAt(0);
file = new FileStream("test2.xlsx", FileMode.Create);//写入excel
workbook.Write(file);
file.Close();
}
}
执行完成后,使用鼠标打开test1.xlsx文件,报丢失信息错误
也不是所有的xlsx文件这样,只有极少数xlsx文件没事,大部分xlsx文件是这样,附件中我上传了一个有问题的xlsx的文件
Comments: ** Comment from web user: tonyqus **
class Program
{
static void Main(string[] args)
{
FileStream file = new FileStream("test1.xlsx", FileMode.Open);//读入excel模板
IWorkbook workbook = new XSSFWorkbook(file);
workbook.RemoveSheetAt(0);
file = new FileStream("test2.xlsx", FileMode.Create);//写入excel
workbook.Write(file);
file.Close();
}
}
执行完成后,使用鼠标打开test1.xlsx文件,报丢失信息错误
也不是所有的xlsx文件这样,只有极少数xlsx文件没事,大部分xlsx文件是这样,附件中我上传了一个有问题的xlsx的文件
Comments: ** Comment from web user: tonyqus **
经测试,你的test1.xlsx文件使用NPOI 2.1.3删除Sheet1之后用Excel 2010打开是正常的。无法重现你说的错误!请确认NPOI版本正确替换为最新版,谢谢!