Click here to Skip to main content
15,031,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to add rows in excel sheet using OpenXML

Trying to insert rows in a table in excel sheet before the last row.
Implementing with following logic.

Could any please help me to achieve this.

Sheet sheet = null;
SheetData sheetData;
DocumentFormat.OpenXml.UInt32Value sheetId;
WorksheetPart worksheetPart = null;

sheet = myWorkbook.WorkbookPart.Workbook.GetFirstChild<sheets>().Elements<sheet>().First(s => s.Name.Value.Equals(“ExcelSheetName”, StringComparison.OrdinalIgnoreCase));
worksheetPart = (WorksheetPart)myWorkbook.WorkbookPart.GetPartById(sheet.Id.Value);
sheetData = worksheetPart.Worksheet.GetFirstChild<sheetdata>();

//Trying following logic
int insertrow =3;
sheetId = UInt32Value.FromUInt32((uint)insertrow);
Row row = new Row() { RowIndex = sheetId };

Could anyone please provide some help.
ZurdoDev 16-May-14 7:07am
Where are you stuck?
JainPrince 16-May-14 7:27am
Above logic didn't worked, and not inserted the row.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900