Incorrect row selected for headers, incorrect header row number returned from getHeaderRow()
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #2817481. --> Reported by: [cruno](https://www.drupal.org/user/2287656) >>> <p>When I tried to import the header row was not being selected for column names, but rather the row below it. I just changed the integer for getting the value from 2 to 1.</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">public function </span><span style="color: #0000BB">getHeaders</span><span style="color: #007700">() {<br>&nbsp; if (!isset(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headers</span><span style="color: #007700">)) {<br>&nbsp;&nbsp;&nbsp; for (</span><span style="color: #0000BB">$col </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$col </span><span style="color: #007700">&lt; </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getColumnsCount</span><span style="color: #007700">(); ++</span><span style="color: #0000BB">$col</span><span style="color: #007700">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$value </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getWorksheet</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getCellByColumnAndRow</span><span style="color: #007700">(</span><span style="color: #0000BB">$col</span><span style="color: #007700">, </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getHeaderRow</span><span style="color: #007700">() + </span><span style="color: #0000BB">1</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getValue</span><span style="color: #007700">();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (isset(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headers</span><span style="color: #007700">[</span><span style="color: #0000BB">$value</span><span style="color: #007700">])) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new \</span><span style="color: #0000BB">RuntimeException</span><span style="color: #007700">(</span><span style="color: #DD0000">"Table header '</span><span style="color: #007700">{</span><span style="color: #0000BB">$value</span><span style="color: #007700">}</span><span style="color: #DD0000">' is duplicated."</span><span style="color: #007700">);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headers</span><span style="color: #007700">[</span><span style="color: #0000BB">$value</span><span style="color: #007700">] = </span><span style="color: #0000BB">$col</span><span style="color: #007700">;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headers</span><span style="color: #007700">;<br>}<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>I also noticed getHeaderRow() was not returning anything so I appended the line with a return.</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #007700">public function </span><span style="color: #0000BB">getHeaderRow</span><span style="color: #007700">() {<br>&nbsp; return </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headerRow</span><span style="color: #007700">;<br>}<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div>
issue