简体   繁体   中英

Change Excel Column Labels in C# (Interop.Excel)

Im trying to create and open a new Excel File on a ButtonClick event without saving it.

Code is working properly, but i need to change the Column labels (not the first row) of the first 10 Columns from A, B, C, D.. to Country1, Country2, Country3..

I cant find an example on the web, can you help me?

This is the Code that i wrote, it creates an Excel and Open it when someone calls the ButtonClick event:

private void Button3_Click(object sender, EventArgs e){
            ExcelApp.Application excelApp = new ExcelApp.Application();
            ExcelApp.Workbook excelWorkBook = excelApp.Workbooks.Add();
            ExcelApp.Worksheet excelWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelWorkBook.ActiveSheet;
            excelWorkSheet.Name = "Travel";
            excelApp.Visible = true;}

As far as I know thats not possible because Excel is also working internally with those column declarations.

All you can do is insert some sort of header row in the first row or where you want to have it and you this one...

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