简体   繁体   中英

how to move entire existing excel range to one row down using interop in C#

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM