Skip to content

Commit

Permalink
Changed normalizeColumn to 1-based column index
Browse files Browse the repository at this point in the history
  • Loading branch information
devOp1 committed Dec 8, 2022
1 parent d4c7d53 commit 69e67d9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ExcelSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected function renderTitle()
$titles = $this->normalizeIndex($this->getTitles());
if ($titles) {
$keys = array_keys($titles);
$col = array_shift($keys) + 1; // Add 1 because PhpSpreadsheet is 1-based
$col = array_shift($keys);
foreach ($titles as $title) {
$this->_sheet->setCellValueByColumnAndRow($col++, $this->_row, $title);
}
Expand Down Expand Up @@ -265,7 +265,7 @@ protected function renderRows()
protected function renderRow($data, $row, $formats, $formatters, $callbacks, $types)
{
foreach (array_values($data) as $i => $value) {
$col = $i + self::normalizeColumn($this->startColumn) + 1; // Add 1 because PhpSpreadsheet is 1-based
$col = $i + self::normalizeColumn($this->startColumn);
if (isset($formatters[$col]) && is_callable($formatters[$col])) {
$value = call_user_func($formatters[$col], $value, $row, $data);
}
Expand Down Expand Up @@ -307,12 +307,12 @@ protected function normalizeIndex($data)
/**
* @param int|string $column the column either as int or as string. If
* numeric, the startColumn offset will be added.
* @return int the normalized numeric column index (0-based).
* @return int the normalized numeric column index (1-based).
*/
public function normalizeColumn($column)
{
if (is_string($column)) {
return \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($column) - 1;
return \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($column);
} else {
return $column + self::normalizeColumn($this->startColumn);
}
Expand Down

0 comments on commit 69e67d9

Please sign in to comment.