Search code examples
c#.netexcel-dna

how to add entire column using excel-dna in C#


Need to open a existing xlsx where a ribben menu and a button require. on click of button need to add 9 blank columns. so shift whole A column to right keep adding 9 blank columns then update them with some calculation.calculation is a lator part , not able to add blank columns

Added menu and button and on click of button tried below code.

var app = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
app.Selection.Insert();

when excel open and if i select whole column manually and click on button it add a blank column and shift A to right ... now not sure how to select whole column using code.

tried few thing but not selecting

 XlCall.Excel(XlCall.xlcSelectEnd, 4);
        ExcelReference selection = 
(ExcelReference)XlCall.Excel(XlCall.xlfSelection);

var row = selection.RowFirst;
var col = selection.ColumnFirst;
var col1 = selection.ColumnLast;
//var val1 = selection.GetValue();
//selection.SetValue(343443);

var activeCell = new ExcelReference(0, row, 0, 0);
app.Selection.Insert();

but not selecting .. please advise how to add blank column.


Solution

  •     app.ActiveSheet.Columns("A:A").Select()