在C#中,以下方案汇编和操作,但在Excel输出档案中没有写任何东西。
我不使用<代码>。 开放XmlWriter,但我从记忆中抽出,因此我不得不转向<代码>。 开放式XmlWriter ,http://blogs.msdn.com/brian_jones/archive/06/22/even-large-excel-files-with-the-open-xml-sdk.aspx”rel=“nofollow” http://blogs.msdn.com/brian_jones/archive/06/22/even-text--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();
}
}
}
为什么没有写任何产出?