【问题标题】:ClosedXml Range ErrorClosedXml 范围错误
【发布时间】:2017-04-06 18:54:48
【问题描述】:

我正在使用 ClosedXml,但在尝试创建时出现以下错误 范围表中的一系列标题。

单元格 A13 和 P13 超出范围 ''SalesOrderHeaderId_1'!A7:P8'。

这是我用来尝试创建范围的 C# 代码:

var sohRngTable = ws.Range("A7:P8");
var sohRngHeaders = sohRngTable.Range("A7:P7");

在尝试创建 sohRngHeaders 的第二行失败,它的行为就像工作表有一些默认大小,但我不确定,我不知道如何更改它或克服这个错误。

【问题讨论】:

    标签: c# excel closedxml


    【解决方案1】:

    地址是相对于父范围的,所以你必须使用:

    var sohRngHeaders = sohRngTable.Range("A1:P1");
    

    这在您的comment 中的documentation you also linked to 中的 cmets 中对另一个答案进行了解释:

    // From another range
    var rngDates = rngTable.Range("D3:D5");   // The address is relative to rngTable (NOT the worksheet)
    var rngNumbers = rngTable.Range("E3:E5"); // The address is relative to rngTable (NOT the worksheet)
    
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

    【讨论】:

    • 我们可以在项目中使用您对 ClosedXML 的良好了解。如果你有时间,也请在 GitHub 页面上帮忙解答问题。
    猜你喜欢
    • 2017-06-27
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多