c# - 获取范围的绝对地址

标签 c# .net epplus

在旧式 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/

相关文章:

c# - Entity Framework 3.5 动态创建实体

c# - WebApi 2 GET 在参数中有特殊字符

c# - MongoDB 和 C# - 检查文档是否存在,如果不插入它

c# - 如何过滤掉catch block

c# - 将 .XLSX 输出到响应时出现 EPPlus 错误

.net - EPPlus 无效地址格式错误

c# - 在对象列表中查找第一个匹配的字符串值

c# - imageList.Draw 不会以不同的尺寸绘制?

.net - Windows Azure 与 Amazon EC2

c# - 使用 EPPlus 命名工作表