ClosedXml范围错误

我正在使用ClosedXml,并试图从范围表中创build一个范围的头时出现以下错误。

单元格A13和P13在“SalesOrderHeaderId_1”!A7:P8'范围之外。

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

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

它尝试创buildsohRngHeaders的第二行失败,它的行为像一个工作表的默认大小,但我不知道,我不知道如何改变它或通过这个错误。

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

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

这在你的评论中也链接到另一个答案的文档的评论中解释:

 // 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) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^