Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
如果您需要做的只是在末尾添加一个空白行,并且您不关心行索引处是否已存在行,那么以下内容应该适合您:
public static void InsertRow(WorksheetPart worksheetPart) { SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>(); Row lastRow = sheetData.Elements<Row>().LastOrDefault(); if (lastRow != null) { sheetData.InsertAfter(new Row() { RowIndex = (lastRow.RowIndex + 1) }, lastRow); } else { sheetData.Insert(new Row() { RowIndex = 0 }); } }
对于 OpenXML SDK 2.5 (Runtime) v4.0.30319 有没有 Insert 方法,因此使用 InsertAt 如下:
Insert
InsertAt
... } else { sheetData.InsertAt(new Row() { RowIndex = 0 }, 0); } }
If all you need to do is add a blank row to the end and you don't care if a row already exists at the row index, then the following should work for you:
For OpenXML SDK 2.5 (Runtime) v4.0.30319 there is no Insert method, thus use InsertAt as follows:
如果您使用 OpenXML SDK 2.5(运行时)v4.0.30319,则没有 Insert 方法,但可以使用 InsertAt 代替,如下所示:
sheetData.InsertAt(new Row() { RowIndex = 0 }, 0);
If you use OpenXML SDK 2.5 (Runtime) v4.0.30319 there is no Insert method, but one can use InsertAt instead as follows:
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
如果您需要做的只是在末尾添加一个空白行,并且您不关心行索引处是否已存在行,那么以下内容应该适合您:
对于 OpenXML SDK 2.5 (Runtime) v4.0.30319 有没有
Insert
方法,因此使用InsertAt
如下:If all you need to do is add a blank row to the end and you don't care if a row already exists at the row index, then the following should work for you:
For OpenXML SDK 2.5 (Runtime) v4.0.30319 there is no
Insert
method, thus useInsertAt
as follows:如果您使用 OpenXML SDK 2.5(运行时)v4.0.30319,则没有
Insert
方法,但可以使用InsertAt
代替,如下所示:If you use OpenXML SDK 2.5 (Runtime) v4.0.30319 there is no
Insert
method, but one can useInsertAt
instead as follows: