how to move entire existing excel range to one row down using interop in C#?
I need to add a header in 1st row of existing excel which has only data.I want to move the entire rangel one setup down programatically in C#.
I saw moving a cell stuff,but moving the entrire range was not clear. could you please help me with it.
I agree if you are running on a server, CloseXML is a better solution, but if you want to go the interop way:
Here is the code to add a row and shift the existing data down by one row.
// Inserts a new row at the beginning of the sheet
Microsoft.Office.Interop.Excel.Range a1 = sheet.get_Range( "A1", Type.Missing );
a1.EntireRow.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown,
Type.Missing );
After you have inserted your new row at the top, you can add the headers to the cells.
I assume you know how to open and access the sheets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With