在旧式 Excel Interop 中,我可以使用以下代码生成绝对地址并在公式中使用它:
range.Formula = $"=sum({myRange.Address[false, true]})";
这行的 EPPlus 等价物是什么,以获得绝对地址(按需使用绝对行和/或列)?
最佳答案
对于仅使用 EPPlus 方法的方法,有返回绝对地址的静态方法,例如 ExcelCellBase.GetAddress
(带有几个重载):
public abstract class ExcelCellBase
{
public static string GetAddress(
int Row,
int Column,
bool Absolute
);
public static string GetAddress(
int Row,
bool AbsoluteRow,
int Column,
bool AbsoluteCol
);
public static string GetAddress(
int FromRow,
int FromColumn,
int ToRow,
int ToColumn,
bool FixedFromRow,
bool FixedFromColumn,
bool FixedToRow,
bool FixedToColumn
);
/* ... and others, see comments */
}
扩展方法可以像这个一样简单:
public static class EpPlusExtensions
{
public static string GetAddress(
this ExcelRangeBase range,
bool absoluteRow = false,
bool absoluteColumn = false)
{
return ExcelCellBase.GetAddress(
range.Start.Row,
range.Start.Column,
range.End.Row,
range.End.Column,
absoluteRow,
absoluteColumn,
absoluteRow,
absoluteColumn);
}
}
关于c# - 获取范围的绝对地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57809684/