【发布时间】:2017-11-07 12:08:52
【问题描述】:
我有一个非常大的 Excel 文件,我需要在其中每行追加 100 个新单元格。 因为 OpenXML DOM 方法给了我一个 OutOfMemory 异常,所以我需要为我的项目使用 OpenXmlWriter。
谁能告诉我如何使用 OpenXmlWriter 将单元格附加到一行?
这是我使用 DOM 方法的代码:
int nRowCounter = 0;
foreach (Row row in sheetData.Elements<Row>())
{
// skip first row
nRowCounter++;
if (nRowCounter == 1)
continue;
string uniqueID = row.Elements<Cell>().First().InnerText;
string[] branchenOfId = crmConnector.GetBranchenFromCrm(uniqueID, "");
if (listSelectedBranchen.Any() && !branchenOfId.Intersect(listSelectedBranchen).Any() && nBranchenIndex == 1)
{
rowsToRemove.Add(row.RowIndex.Value);
continue;
}
string cellValue = "";
if (branchenOfId.Contains(strName))
cellValue = strName;
row.Append(new Cell() { DataType = CellValues.String, CellValue = new CellValue(cellValue) });
}
【问题讨论】:
标签: c# excel openxml openxml-sdk