Epplus 获取列 header
Epplus get the column header
我想了解如何使用 Epplus 获取列字母。我知道 Address 将 return 列字母和行号,而 FullAddress 将添加 sheet 名称,但我没有看到仅列字母的 object。
?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"
?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
class,它具有静态方法 GetColumnLetter
来检索与提供的基于 1 的列索引对应的字母。
public static string GetColumnLetter(int column)
下面的调用将return列字母A
.
String columnLetter = OfficeOpenXml.ExcelCellAddress.GetColumnLetter(1); // A
我想了解如何使用 Epplus 获取列字母。我知道 Address 将 return 列字母和行号,而 FullAddress 将添加 sheet 名称,但我没有看到仅列字母的 object。
?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"
?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
class,它具有静态方法 GetColumnLetter
来检索与提供的基于 1 的列索引对应的字母。
public static string GetColumnLetter(int column)
下面的调用将return列字母A
.
String columnLetter = OfficeOpenXml.ExcelCellAddress.GetColumnLetter(1); // A