0
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.

17
  • Can you try like this -> r.EntireColumn.Insert() Commented Aug 1, 2017 at 14:04
  • Yeah,I tried it,but it didn't work neither. Commented Aug 1, 2017 at 14:06
  • what do you get in the Console from printing r.Address? Commented Aug 1, 2017 at 14:06
  • And you may try to see Console.WriteLine(r.Parent.Name) to see whether you are refering the correct worksheet. Commented Aug 1, 2017 at 14:09
  • 1
    Close this question,I don't want this topic wasting time. Commented Aug 9, 2017 at 12:14

1 Answer 1

1

This is how you insert a column:

r.EntireColumn.Insert()

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

Sign up to request clarification or add additional context in comments.

2 Comments

Well,I forgot to insert column in other sheets in a loop .So I always get the wrong result.Thank you,again.
I only have the first sheet inserted the column,but I have never checked it until now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.