在 C# 中,以下程序编译并运行,但它不会在 excel 输出文件中写入任何内容。
我让它在没有的情况下工作,OpenXmlWriter
但我开始内存不足,所以我必须OpenXmlWriter
根据这个http://blogs.msdn.com/b/brian_jones/archive/2010/06/22/writing-large-excel切换到-files-with-the-open-xml-sdk.aspx
class Program
{
static void Main(string[] args)
{
File.Copy("book.xlsx", "output.xlsx", true);
WriteValuesSAX("output.xlsx", 10, 10);
}
static void WriteValuesSAX(string filename, int numRows, int numCols)
{
using (SpreadsheetDocument myDoc =
SpreadsheetDocument.Open(filename, true))
{
WorkbookPart workbookPart = myDoc.WorkbookPart;
WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
OpenXmlWriter writer = OpenXmlWriter.Create(worksheetPart);
Row r = new Row();
Cell c = new Cell();
CellValue v = new CellValue("Test");
c.AppendChild(v);
writer.WriteStartElement(new SheetData());
for (int row = 0; row < numRows; row++)
{
writer.WriteStartElement(r);
for (int col = 0; col < numCols; col++)
{
writer.WriteElement(c);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.Close();
}
}
}
为什么它不写任何东西来输出?