张绍峰
张绍峰

Reputation: 311

Insert Column in Excel doesn't work in C#

using Excel = Microsoft.Office.Interop.Excel;


Excel.Range r = sheet.get_Range(ExcelAssistant.c1ToA(Column_Date + i) + Row_Date_Insert, ExcelAssistant.c1ToA(Column_Date + i) + (Row_Date_Insert + sheet.UsedRange.Rows.Count));

Console.WriteLine("range r property" + r.Address);

r.Insert(Excel.XlInsertShiftDirection.xlShiftToRight,Missing.Value);
r.Insert();
sheet.Columns[Column_Date + i].insert();

ExcelAssistant is an Excel Util class and it has static method c1ToA to transfer the interger of the column number into the "ABC" Format.

I use the Console.WriteLine to ensure I point to correct position.

Then I tried several insert method above but none works.

What' wrong?

Any help may be appreciated.

Upvotes: 0

Views: 2130

Answers (1)

Vityata
Vityata

Reputation: 43585

This is how you insert a column:

r.EntireColumn.Insert()

Take a look here as well: Insert Columns between columns in excel

Upvotes: 1

Related Questions