diff --git a/CHANGELOG.md b/CHANGELOG.md index 68aad0c1..1867f097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix for Issue [#1495](https://github.com/PHPOffice/PhpSpreadsheet/issues/1495) (Sheet index being changed when multiple sheets are used in formula) [#1500]((https://github.com/PHPOffice/PhpSpreadsheet/pull/1500)) - Fix for Issue [#1533](https://github.com/PHPOffice/PhpSpreadsheet/issues/1533) (A reference to a cell containing a string starting with "#" leads to errors in the generated xlsx.) [#1534](https://github.com/PHPOffice/PhpSpreadsheet/pull/1534) - Xls Writer - Correct Timestamp Bug [#1493](https://github.com/PHPOffice/PhpSpreadsheet/pull/1493) +- Don't ouput row and columns without any cells in HTML writer [#1235](https://github.com/PHPOffice/PhpSpreadsheet/issues/1235) ### Added - Add support for IFS() logical function [#1442](https://github.com/PHPOffice/PhpSpreadsheet/pull/1442) diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php index eb50c456..ec8fec7d 100644 --- a/src/PhpSpreadsheet/Writer/Html.php +++ b/src/PhpSpreadsheet/Writer/Html.php @@ -449,22 +449,19 @@ class Html extends BaseWriter foreach ($sheets as $sheet) { // Write table header $html .= $this->generateTableHeader($sheet); + // Get worksheet dimension - $dimension = explode(':', $sheet->calculateWorksheetDimension()); - $dimension[0] = Coordinate::coordinateFromString($dimension[0]); - $dimension[0][0] = Coordinate::columnIndexFromString($dimension[0][0]); - $dimension[1] = Coordinate::coordinateFromString($dimension[1]); - $dimension[1][0] = Coordinate::columnIndexFromString($dimension[1][0]); + [$min, $max] = explode(':', $sheet->calculateWorksheetDataDimension()); + [$minCol, $minRow] = Coordinate::coordinateFromString($min); + $minCol = Coordinate::columnIndexFromString($minCol); + [$maxCol, $maxRow] = Coordinate::coordinateFromString($max); + $maxCol = Coordinate::columnIndexFromString($maxCol); - // row min,max - $rowMin = $dimension[0][1]; - $rowMax = $dimension[1][1]; - - [$theadStart, $theadEnd, $tbodyStart] = $this->generateSheetStarts($sheet, $rowMin); + [$theadStart, $theadEnd, $tbodyStart] = $this->generateSheetStarts($sheet, $minRow); // Loop through cells - $row = $rowMin - 1; - while ($row++ < $rowMax) { + $row = $minRow - 1; + while ($row++ < $maxRow) { [$cellType, $startTag, $endTag] = $this->generateSheetTags($row, $theadStart, $theadEnd, $tbodyStart); $html .= $startTag; @@ -473,8 +470,8 @@ class Html extends BaseWriter // Start a new rowData $rowData = []; // Loop through columns - $column = $dimension[0][0]; - while ($column <= $dimension[1][0]) { + $column = $minCol; + while ($column <= $maxCol) { // Cell exists? if ($sheet->cellExistsByColumnAndRow($column, $row)) { $rowData[$column] = Coordinate::stringFromColumnIndex($column) . $row; @@ -557,7 +554,7 @@ class Html extends BaseWriter * * @codeCoverageIgnore */ - private function extendRowsForCharts(Worksheet $pSheet, $row) + private function extendRowsForCharts(Worksheet $pSheet, int $row) { $rowMax = $row; $colMax = 'A'; @@ -582,7 +579,7 @@ class Html extends BaseWriter return [$rowMax, $colMax, $anyfound]; } - private function extendRowsForChartsAndImages(Worksheet $pSheet, $row) + private function extendRowsForChartsAndImages(Worksheet $pSheet, int $row): string { [$rowMax, $colMax, $anyfound] = $this->extendRowsForCharts($pSheet, $row); @@ -1169,7 +1166,7 @@ class Html extends BaseWriter * Generate table header. * * @param Worksheet $pSheet The worksheet for the table we are writing - * @param bool $showid whether or not to add id to table tag + * @param bool $showid whether or not to add id to table tag * * @return string */ @@ -1182,8 +1179,6 @@ class Html extends BaseWriter $id = $showid ? "id='sheet$sheetIndex'" : ''; if ($showid) { $html .= "