2

I am using ClosedXml and I am getting the following error when trying create a range of headers from a range table.

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

Here is the C# Code I am using to try and create the range:

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

It fails on the second line trying to create sohRngHeaders, it acts like there is some default size for a worksheet but I am not sure and I can't figure out how to change it or get past this error.

OutOFTouch
  • 1,017
  • 3
  • 13
  • 30

1 Answers1

1

The address is relative to the parent range, so you have to use:

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

This is explained in the comments in the documentation you also linked to in your comment to another answer:

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

                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Community
  • 1
  • 1
Raidri
  • 17,258
  • 9
  • 62
  • 65
  • 1
    We could use your good knowledge of ClosedXML in the project. If you have time, please help answer issues on the GitHub page too. – Francois Botha Apr 07 '17 at 12:01