C# Epplus获取列标题

C# Epplus获取列标题,c#,excel,datatable,epplus,C#,Excel,Datatable,Epplus,我想了解如何使用Epplus获取列字母。我知道Address将返回列字母和行号,FullAddress将添加工作表名称,但我没有看到仅列字母的对象 ?sheet.Cells[index2, index3].Address "J2" ?sheet.Cells[index2, index3].FormulaR1C1 "" ?sheet.Cells[index2, index3].FullAddress "'Sheet1'!J2" ?sheet.Cells[index2, index3].Ful

我想了解如何使用Epplus获取列字母。我知道Address将返回列字母和行号,FullAddress将添加工作表名称,但我没有看到仅列字母的对象

?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

你已经知道index3了。你有这一列字母

public static class IntExtension
{
    public static string ToExcelColumn(this int i)
    {
        string column = string.Empty;

        if (i / 26m > 1)
        {
            int letter = (int)i / 26;
            column = ((char)(65 + letter - 1)).ToString();
            i -= letter * 26;
        }

        column += ((char)(65 + i - 1)).ToString();

        return column;
    }
}

只需调用
index3.ToExcelColumn()

EPPlus包含一个
ExcelCellAddress
类,该类使用静态方法
GetColumnLetter
检索与提供的基于1的列索引相对应的字母

public static string GetColumnLetter(int column)
以下调用将返回列字母
A

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

这仅限于
A
ZZ
。这样做更有意义
XFD
是Excel中最后一个(通常)可寻址列。这应该是可接受的答案。这对我有帮助。谢谢