Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# PhpSpreadsheet

[![Build Status](https://github.com/PHPOffice/PhpSpreadsheet/workflows/main/badge.svg)](https://github.com/PHPOffice/PhpSpreadsheet/actions)
[![Code Quality](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/PHPOffice/PhpSpreadsheet/?branch=master)
[![Code Coverage](https://coveralls.io/repos/github/PHPOffice/PhpSpreadsheet/badge.svg?branch=master)](https://coveralls.io/github/PHPOffice/PhpSpreadsheet?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/PHPOffice/PhpSpreadsheet)](https://packagist.org/packages/phpoffice/phpspreadsheet)
[![Latest Stable Version](https://img.shields.io/github/v/release/PHPOffice/PhpSpreadsheet)](https://packagist.org/packages/phpoffice/phpspreadsheet)
[![License](https://img.shields.io/github/license/PHPOffice/PhpSpreadsheet)](https://packagist.org/packages/phpoffice/phpspreadsheet)
Expand All @@ -11,6 +10,17 @@
PhpSpreadsheet is a library written in pure PHP and offers a set of classes that
allow you to read and write various spreadsheet file formats such as Excel and LibreOffice Calc.

This branch (release390) is maintained (for security and some bug fixes), but it is *not* the latest version of PhpSpreadsheet, and may therefore lack features and bug fixes found in the latest version.

## PHP Version Support

LTS: For maintained branches, support for PHP versions will only be maintained for a period of six months beyond the
[end of life](https://www.php.net/supported-versions) of that PHP version.

Currently the required PHP minimum version is PHP __8.1__, and we [will support that version](https://www.php.net/supported-versions.php) until 30th June 2026.

See the `composer.json` for other requirements.

## Installation

See the [install instructions](https://phpspreadsheet.readthedocs.io/en/latest/#installation).
Expand Down
3 changes: 2 additions & 1 deletion infra/LocaleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\Row;
Expand Down Expand Up @@ -276,7 +277,7 @@ protected function mapLanguageColumns(Worksheet $translationWorksheet): array
$this->log("Mapping Languages for {$sheetName}:");

$baseColumn = self::ENGLISH_REFERENCE_COLUMN;
$languagesList = $translationWorksheet->getColumnIterator(++$baseColumn);
$languagesList = $translationWorksheet->getColumnIterator(StringHelper::stringIncrement($baseColumn));

$languageNameMap = [];
foreach ($languagesList as $languageColumn) {
Expand Down
3 changes: 2 additions & 1 deletion samples/Basic1/13_Calculation.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

mt_srand(1234567890);
Expand Down Expand Up @@ -155,7 +156,7 @@

// Calculated data
$helper->log('Calculated data');
for ($col = 'B'; $col != 'G'; ++$col) {
for ($col = 'B'; $col != 'G'; StringHelper::stringIncrement($col)) {
for ($row = 14; $row <= 41; ++$row) {
$formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue();
if (
Expand Down
3 changes: 2 additions & 1 deletion samples/Basic1/13_CalculationCyclicFormulae.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

require __DIR__ . '/../Header.php';
Expand All @@ -21,7 +22,7 @@
// Calculated data
$helper->log('Calculated data');
for ($row = 1; $row <= 2; ++$row) {
for ($col = 'A'; $col != 'C'; ++$col) {
for ($col = 'A'; $col != 'C'; StringHelper::stringIncrement($col)) {
$formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue();
if (
is_string($formula)
Expand Down
3 changes: 2 additions & 1 deletion samples/Basic3/39_Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

require __DIR__ . '/../Header.php';
Expand Down Expand Up @@ -57,7 +58,7 @@ function transpose(string $value): array
$spreadsheet->getActiveSheet()
->setCellValue($continentColumn . ($key + 1), $continent);

++$column;
StringHelper::stringIncrement($column);
}

// Hide the dropdown data
Expand Down
7 changes: 4 additions & 3 deletions samples/ConditionalFormatting/05_Date_Comparisons.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Color;
Expand Down Expand Up @@ -96,7 +97,7 @@
->fromArray($dateFunctionArray, null, 'B1', true);
$spreadsheet->getActiveSheet()
->fromArray($dateTitleArray, null, 'A2', true);
for ($column = 'B'; $column !== 'L'; ++$column) {
for ($column = 'B'; $column !== 'L'; StringHelper::stringIncrement($column)) {
$spreadsheet->getActiveSheet()
->fromArray($dataArray, null, "{$column}2", true);
}
Expand All @@ -116,7 +117,7 @@

// Set conditional formatting rules and styles
$helper->log('Define conditional formatting and set styles');
for ($column = 'B'; $column !== 'L'; ++$column) {
for ($column = 'B'; $column !== 'L'; StringHelper::stringIncrement($column)) {
$wizardFactory = new Wizard("{$column}2:{$column}19");
/** @var Wizard\DateValue $dateWizard */
$dateWizard = $wizardFactory->newRule(Wizard::DATES_OCCURRING);
Expand All @@ -139,7 +140,7 @@
$helper->log('Set some additional styling for date formats');

$spreadsheet->getActiveSheet()->getStyle('B:B')->getNumberFormat()->setFormatCode('ddd dd-mmm-yyyy');
for ($column = 'A'; $column !== 'L'; ++$column) {
for ($column = 'A'; $column !== 'L'; StringHelper::stringIncrement($column)) {
if ($column !== 'A') {
$spreadsheet->getActiveSheet()->getStyle("{$column}:{$column}")
->getNumberFormat()->setFormatCode('ddd dd-mmm-yyyy');
Expand Down
3 changes: 2 additions & 1 deletion samples/LookupRef/VLOOKUP.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

require __DIR__ . '/../Header.php';
Expand Down Expand Up @@ -40,7 +41,7 @@
$worksheet->getCell('I5')->setValue('=VLOOKUP(I3, B3:E9, 4, FALSE)');
$worksheet->getCell('J5')->setValue('=VLOOKUP(J3, B3:E9, 4, FALSE)');

for ($column = 'H'; $column !== 'K'; ++$column) {
for ($column = 'H'; $column !== 'K'; StringHelper::stringIncrement($column)) {
for ($row = 4; $row <= 5; ++$row) {
$cell = $worksheet->getCell("{$column}{$row}");
$helper->log("{$column}{$row}: " . $cell->getValue() . ' => ' . $cell->getCalculatedValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
use Stringable;

Expand Down Expand Up @@ -177,8 +178,8 @@ private function getColumns(Cell $cell, array $tableRange): array
$cellReference = $cell->getCoordinate();

$columns = [];
$lastColumn = ++$tableRange[1][0];
for ($column = $tableRange[0][0]; $column !== $lastColumn; ++$column) {
$lastColumn = StringHelper::stringIncrement($tableRange[1][0]);
for ($column = $tableRange[0][0]; $column !== $lastColumn; StringHelper::stringIncrement($column)) {
$columns[$column] = $worksheet
->getCell($column . ($this->headersRow ?? ($this->firstDataRow - 1)))
->getCalculatedValue();
Expand Down
12 changes: 6 additions & 6 deletions src/PhpSpreadsheet/Cell/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function getCalculatedValue(bool $resetLog = true): mixed
}
}
}
++$newColumn;
StringHelper::stringIncrement($newColumn);
}
++$newRow;
} else {
Expand All @@ -478,7 +478,7 @@ public function getCalculatedValue(bool $resetLog = true): mixed
}
}
}
++$newColumn;
StringHelper::stringIncrement($newColumn);
}
if ($spill) {
break;
Expand All @@ -501,10 +501,10 @@ public function getCalculatedValue(bool $resetLog = true): mixed
$minRow = (int) $matches[2];
// https://github.com/phpstan/phpstan/issues/11602
$maxCol = $matches[4]; // @phpstan-ignore-line
++$maxCol;
StringHelper::stringIncrement($maxCol);
$maxRow = (int) $matches[5]; // @phpstan-ignore-line
for ($row = $minRow; $row <= $maxRow; ++$row) {
for ($col = $minCol; $col !== $maxCol; ++$col) {
for ($col = $minCol; $col !== $maxCol; StringHelper::stringIncrement($col)) {
if ("$col$row" !== $coordinate) {
$thisworksheet->getCell("$col$row")->setValue(null);
}
Expand All @@ -529,14 +529,14 @@ public function getCalculatedValue(bool $resetLog = true): mixed
if ($row !== $newRow || $column !== $newColumn) {
$thisworksheet->getCell($newColumn . $newRow)->setValue($resultValue);
}
++$newColumn;
StringHelper::stringIncrement($newColumn);
}
++$newRow;
} else {
if ($row !== $newRow || $column !== $newColumn) {
$thisworksheet->getCell($newColumn . $newRow)->setValue($resultRow);
}
++$newColumn;
StringHelper::stringIncrement($newColumn);
}
}
$thisworksheet->getCell($column . $row);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private function loadStringOrFile2(string $filename, Spreadsheet $spreadsheet, b
// Set cell value
$sheet->getCell($columnLetter . $outRow)->setValue($rowDatum);
}
++$columnLetter;
StringHelper::stringIncrement($columnLetter);
}
$rowData = self::getCsv($fileHandle, 0, $delimiter, $this->enclosure, $this->escapeCharacter);
++$currentRow;
Expand Down
17 changes: 9 additions & 8 deletions src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
use PhpOffice\PhpSpreadsheet\Helper\Html as HelperHtml;
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
Expand Down Expand Up @@ -525,7 +526,7 @@ private function processDomElementTable(Worksheet $sheet, int &$row, string &$co
$this->processDomElement($child, $sheet, $row, $column, $cellContent);
$column = $this->releaseTableStartColumn();
if ($this->tableLevel > 1) {
++$column;
StringHelper::stringIncrement($column);
} else {
++$row;
}
Expand All @@ -538,7 +539,7 @@ private function processDomElementTr(Worksheet $sheet, int &$row, string &$colum
{
if ($child->nodeName === 'col') {
$this->applyInlineStyle($sheet, -1, $this->currentColumn, $attributeArray);
++$this->currentColumn;
StringHelper::stringIncrement($this->currentColumn);
} elseif ($child->nodeName === 'tr') {
$column = $this->getTableStartColumn();
$cellContent = '';
Expand Down Expand Up @@ -615,7 +616,7 @@ private function processDomElementDataFormat(Worksheet $sheet, int $row, string
private function processDomElementThTd(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray): void
{
while (isset($this->rowspan[$column . $row])) {
++$column;
StringHelper::stringIncrement($column);
}
$this->processDomElement($child, $sheet, $row, $column, $cellContent);

Expand All @@ -635,7 +636,7 @@ private function processDomElementThTd(Worksheet $sheet, int &$row, string &$col
//create merging rowspan and colspan
$columnTo = $column;
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo;
StringHelper::stringIncrement($columnTo);
}
$range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
Expand All @@ -654,13 +655,13 @@ private function processDomElementThTd(Worksheet $sheet, int &$row, string &$col
//create merging colspan
$columnTo = $column;
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo;
StringHelper::stringIncrement($columnTo);
}
$sheet->mergeCells($column . $row . ':' . $columnTo . $row);
$column = $columnTo;
}

++$column;
StringHelper::stringIncrement($column);
}

protected function processDomElement(DOMNode $element, Worksheet $sheet, int &$row, string &$column, string &$cellContent): void
Expand Down Expand Up @@ -898,7 +899,7 @@ private function applyInlineStyle(Worksheet &$sheet, int $row, string $column, a
} elseif (isset($attributeArray['rowspan'], $attributeArray['colspan'])) {
$columnTo = $column;
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo;
StringHelper::stringIncrement($columnTo);
}
$range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1);
$cellStyle = $sheet->getStyle($range);
Expand All @@ -908,7 +909,7 @@ private function applyInlineStyle(Worksheet &$sheet, int $row, string $column, a
} elseif (isset($attributeArray['colspan'])) {
$columnTo = $column;
for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) {
++$columnTo;
StringHelper::stringIncrement($columnTo);
}
$range = $column . $row . ':' . $columnTo . $row;
$cellStyle = $sheet->getStyle($range);
Expand Down
17 changes: 12 additions & 5 deletions src/PhpSpreadsheet/Reader/Ods.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
Expand Down Expand Up @@ -394,7 +395,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
$spreadsheet->getActiveSheet()
->getColumnDimension($tableColumnString)
->setWidth($columnWidth->toUnit('cm'), 'cm');
++$tableColumnString;
StringHelper::stringIncrement(
$tableColumnString
);
}
}
$tableColumnIndex += $rowRepeats;
Expand Down Expand Up @@ -422,7 +425,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
}

for ($i = 0; $i < $colRepeats; ++$i) {
++$columnID;
StringHelper::stringIncrement($columnID);
}

continue;
Expand All @@ -448,7 +451,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
$lastRow = $rowID + $arrayRow - 1;
$lastCol = $columnID;
while ($arrayCol > 1) {
++$lastCol;
StringHelper::stringIncrement(
$lastCol
);
--$arrayCol;
}
$cellDataRef = "$columnID$rowID:$lastCol$lastRow";
Expand Down Expand Up @@ -612,7 +617,9 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
if ($type !== null) {
for ($i = 0; $i < $colRepeats; ++$i) {
if ($i > 0) {
++$columnID;
StringHelper::stringIncrement(
$columnID
);
}

if ($type !== DataType::TYPE_NULL) {
Expand Down Expand Up @@ -664,7 +671,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
// Merged cells
$this->processMergedCells($cellData, $tableNs, $type, $columnID, $rowID, $spreadsheet);

++$columnID;
StringHelper::stringIncrement($columnID);
}
$rowID += $rowRepeats;

Expand Down
6 changes: 5 additions & 1 deletion src/PhpSpreadsheet/Reader/Slk.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ private function addWidth(Spreadsheet $spreadsheet, string $columnWidth, string
$endCol = Coordinate::stringFromColumnIndex((int) $endCol);
$spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth((float) $columnWidth);
do {
$spreadsheet->getActiveSheet()->getColumnDimension((string) ++$startCol)->setWidth((float) $columnWidth);
$spreadsheet->getActiveSheet()
->getColumnDimension(
StringHelper::stringIncrement($startCol)
)
->setWidth((float) $columnWidth);
} while ($startCol !== $endCol);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -3486,9 +3486,9 @@ private function includeCellRangeFiltered(string $cellRangeAddress): bool
if ($this->getReadFilter() !== null) {
$includeCellRange = false;
$rangeBoundaries = Coordinate::getRangeBoundaries($cellRangeAddress);
++$rangeBoundaries[1][0];
StringHelper::stringIncrement($rangeBoundaries[1][0]);
for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; ++$row) {
for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; ++$column) {
for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; StringHelper::stringIncrement($column)) {
if ($this->getReadFilter()->readCell($column, $row, $this->phpSheet->getTitle())) {
$includeCellRange = true;

Expand Down
Loading