小智 7
假设您使用的是SDK 2.0,我使用此函数做了类似的事情:
private static Row CreateRow(Row refRow, SheetData sheetData)
{
uint rowIndex = refRow.RowIndex.Value;
uint newRowIndex;
var newRow = (Row)refRow.Clone();
/*IEnumerable<Row> rows = sheetData.Descendants<Row>().Where(r => r.RowIndex.Value >= rowIndex);
foreach (Row row in rows)
{
newRowIndex = System.Convert.ToUInt32(row.RowIndex.Value + 1);
foreach (Cell cell in row.Elements<Cell>())
{
string cellReference = cell.CellReference.Value;
cell.CellReference = new StringValue(cellReference.Replace(row.RowIndex.Value.ToString(), newRowIndex.ToString()));
}
row.RowIndex = new UInt32Value(newRowIndex);
}*/
sheetData.InsertBefore(newRow, refRow);
return newRow;
}
Run Code Online (Sandbox Code Playgroud)
我不确定你之前是如何使用InsertBeforeSelf做的,所以也许这并没有太大的改进,但这对我有用.我以为你可以用你的总计行作为参考行.(注释掉的部分是为了你的参考行之后有你想要维护的行.我做了一些修改,但它主要来自这个帖子:http://social.msdn.microsoft.com/Forums/en- US/oxmlsdk/thread/65c9ca1c-25d4-482d-8eb3-91a3512bb0ac)
由于它返回新行,您可以使用该对象,然后使用数据库中的数据编辑单元格值.我希望这至少对尝试这样做的人有所帮助......
| 归档时间: |
|
| 查看次数: |
9248 次 |
| 最近记录: |