Search code examples
c#exceldatatableepplus

Epplus get the column header


I would like to understand how to get the column letter using Epplus. I know that Address will return the column letter and row number and FullAddress will add the sheet name but I don't see an object for just the column letter.

?sheet.Cells[index2, index3].Address
"J2"

?sheet.Cells[index2, index3].FormulaR1C1
""

?sheet.Cells[index2, index3].FullAddress
"'Sheet1'!J2"

?sheet.Cells[index2, index3].FullAddressAbsolute
"'Sheet1'!$J$2"

?sheet.Cells[index2, index3].Rows

Solution

  • EPPlus contains a ExcelCellAddress class which has the static method GetColumnLetter to retrieve the letter corresponding to the supplied 1-based column index.

    public static string GetColumnLetter(int column)
    

    The following call will return column letter A.

    String columnLetter = OfficeOpenXml.ExcelCellAddress.GetColumnLetter(1); // A