【发布时间】:2016-12-12 21:23:57
【问题描述】:
xlWorksheet.GetRow(1).GetCell(2).SetCellValue("Hello");
using (FileStream file = new FileStream("Test.xlsx", FileMode.Create, FileAccess.Write))
{
XLWorkBook.Write(file);
file.Close();
}
我用这段代码编写了excel文件。编写excel后,当我手动打开excel文件时,它已损坏。 我正在使用 NPOI 二进制 2.1.3.1 请告诉如何避免excel被损坏。
【问题讨论】:
-
有
using (),不需要file.Close(),它会自动关闭 -
你的
xlWorkseet是什么类型的? -
是否有人使用 NPOI 使用 Xlsx 编写 excel 表。我需要开源 dll 来访问 xlsx 文件。他们有任何可用的替代开源软件吗..
-
来自 Microsoft 的 OpenXml SDK。它是免费的并且非常强大。但是 NPOI 也应该与 xlsx 一起使用,就像 xls 一样。见stackoverflow.com/questions/16079956/…