gpt4 book ai didi

c# - ClosedXml 范围错误

转载 作者:行者123 更新时间:2023-12-04 20:35:24 24 4
gpt4 key购买 nike

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

The cells A13 and P13 are outside the range ''SalesOrderHeaderId_1'!A7:P8'.



这是我用来尝试创建范围的 C# 代码:
var sohRngTable = ws.Range("A7:P8");
var sohRngHeaders = sohRngTable.Range("A7:P7");

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

最佳答案

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

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

这在 documentation you also linked to 的评论中进行了解释。在您的 comment另一个答案:
// 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)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

关于c# - ClosedXml 范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43263594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com