Skip to content

Commit

Permalink
Merge branch 'master' into issue797
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Jan 22, 2025
2 parents 07fbe9a + ed66270 commit 89b30eb
Show file tree
Hide file tree
Showing 38 changed files with 1,295 additions and 215 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Added

- Nothing yet.
- Methods to get style for row or column. [PR #4317](https://github.com/PHPOffice/PhpSpreadsheet/pull/4317)
- Method for duplicating worksheet in spreadsheet. [PR #4315](https://github.com/PHPOffice/PhpSpreadsheet/pull/4315)

### Changed

Expand All @@ -25,7 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- Nothing yet.
- Ods Reader Sheet Names with Period. [Issue #4311](https://github.com/PHPOffice/PhpSpreadsheet/issues/4311) [PR #4313](https://github.com/PHPOffice/PhpSpreadsheet/pull/4313)
- Mpdf and Tcpdf Hidden Columns and Merged Cells. [Issue #4319](https://github.com/PHPOffice/PhpSpreadsheet/issues/4319) [PR #4320](https://github.com/PHPOffice/PhpSpreadsheet/pull/4320)
- Html Writer Allow mailto. [Issue #4316](https://github.com/PHPOffice/PhpSpreadsheet/issues/4316) [PR #4322](https://github.com/PHPOffice/PhpSpreadsheet/pull/4322)
- Use composer/pcre rather than preg_* in Writer. [PR #4323](https://github.com/PHPOffice/PhpSpreadsheet/pull/4323)

## 2025-01-11 - 3.8.0

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"ext-xmlwriter": "*",
"ext-zip": "*",
"ext-zlib": "*",
"composer/pcre": "^3.3",
"maennchen/zipstream-php": "^2.1 || ^3.0",
"markbaker/complex": "^3.0",
"markbaker/matrix": "^3.0",
Expand Down
160 changes: 80 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/topics/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ loop. This is much faster compared to looping through cells and styling
them individually.

**Tip** If you are styling entire row(s) or column(s), e.g. getStyle('A:A'), it is recommended to use applyFromArray as described below rather than setting the styles individually as described above.
Also, starting with release 3.9.0, you should use getRowStyle or getColumnStyle to get the style for an entire row or column.

There is also an alternative manner to set styles. The following code
sets a cell's style to font bold, alignment right, top border thin and a
Expand Down
27 changes: 23 additions & 4 deletions docs/topics/worksheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,38 @@ insert the clone into the workbook.

```php
$clonedWorksheet = clone $spreadsheet->getSheetByName('Worksheet 1');
$clonedWorksheet->setTitle('Copy of Worksheet 1');
$clonedWorksheet->setTitle('Copy of Worksheet 1'); // must be unique
$spreadsheet->addSheet($clonedWorksheet);
```
Starting with PhpSpreadsheet 3.9.0, this can be done more simply (copied sheet's title will be set to something unique):
```php
$copiedWorksheet = $spreadsheet->duplicateWorksheetByTitle('sheetname');
```

You can also copy worksheets from one workbook to another, though this
is more complex as PhpSpreadsheet also has to replicate the styling
between the two workbooks. The `addExternalSheet()` method is provided for
this purpose.

$clonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
$spreadsheet->addExternalSheet($clonedWorksheet);
```php
$clonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
$clonedWorksheet->setTitle('Copy of Worksheet 1'); // must be unique
$spreadsheet1->addSheet($clonedWorksheet);
$spreadsheet->addExternalSheet($clonedWorksheet);
```
Starting with PhpSpreadsheet 3.8.0, this can be simplified:
```php
$clonedWorksheet = clone $spreadsheet1->getSheetByName('Worksheet 1');
$spreadsheet1->addSheet($clonedWorksheet, null, true);
$spreadsheet->addExternalSheet($clonedWorksheet);
```
Starting with PhpSpreadsheet 3.9.0, this can be simplified even further:
```php
$clonedWorksheet = $spreadsheet1->duplicateWorksheetByTitle('sheetname');
$spreadsheet->addExternalSheet($clonedWorksheet);
```

In both cases, it is the developer's responsibility to ensure that
In the cases commented "must be unique", it is the developer's responsibility to ensure that
worksheet names are not duplicated. PhpSpreadsheet will throw an
exception if you attempt to copy worksheets that will result in a
duplicate name.
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/composer/pcre/extension.neon

parameters:
level: 8
Expand Down
3 changes: 2 additions & 1 deletion samples/Pdf/21b_Pdf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
Expand All @@ -21,7 +22,7 @@ function replaceBody(string $html): string
</body>
EOF;

return preg_replace($bodystring, $bodyrepl, $html) ?? '';
return preg_replace($bodystring, $bodyrepl, $html) ?? throw new SpreadsheetException('preg failed');
}

require __DIR__ . '/../Header.php';
Expand Down
5 changes: 3 additions & 2 deletions samples/Pdf/21c_Pdf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
Expand All @@ -16,7 +17,7 @@ function addHeadersFootersMpdf2000(string $html): string
odd-footer-name: html_myFooter2;
EOF;
$html = preg_replace('/@page page0 {/', $pagerepl, $html) ?? '';
$html = preg_replace('/@page page0 {/', $pagerepl, $html) ?? throw new SpreadsheetException('preg 1 failed');
$bodystring = '/<body>/';
$simulatedBodyStart = Mpdf::SIMULATED_BODY_START;
$bodyrepl = <<<EOF
Expand All @@ -40,7 +41,7 @@ function addHeadersFootersMpdf2000(string $html): string
EOF;

return preg_replace($bodystring, $bodyrepl, $html) ?? '';
return preg_replace($bodystring, $bodyrepl, $html) ?? throw new SpreadsheetException('preg 2 failed');
}

$spreadsheet = new Spreadsheet();
Expand Down
2 changes: 1 addition & 1 deletion samples/Reading_workbook_data/Custom_properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

break;
case 'd': // date
$propertyValue = is_numeric($propertyValue) ? date('l, d<\s\u\p>S</\s\u\p> F Y g:i A', (int) $propertyValue) : '*****INVALID*****';
$propertyValue = is_numeric($propertyValue) ? date('l, j<\s\u\p>S</\s\u\p> F Y g:i A', (int) $propertyValue) : '*****INVALID*****';
$propertyType = 'date';

break;
Expand Down
4 changes: 2 additions & 2 deletions samples/Reading_workbook_data/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// Read the Date when the workbook was created (as a PHP timestamp value)
$creationDatestamp = $spreadsheet->getProperties()->getCreated();
$creationDate = Date::formattedDateTimeFromTimestamp("$creationDatestamp", 'l, d<\s\up>S</\s\up> F Y');
$creationDate = Date::formattedDateTimeFromTimestamp("$creationDatestamp", 'l, j<\s\u\p>S</\s\u\p> F Y');
$creationTime = Date::formattedDateTimeFromTimestamp("$creationDatestamp", 'g:i A');
$helper->log('<b>Created On: </b>' . $creationDate . ' at ' . $creationTime);

Expand All @@ -30,7 +30,7 @@
// Read the Date when the workbook was last modified (as a PHP timestamp value)
$modifiedDatestamp = $spreadsheet->getProperties()->getModified();
// Format the date and time using the standard PHP date() function
$modifiedDate = Date::formattedDateTimeFromTimestamp("$modifiedDatestamp", 'l, d<\s\up>S</\s\up> F Y');
$modifiedDate = Date::formattedDateTimeFromTimestamp("$modifiedDatestamp", 'l, j<\s\u\p>S</\s\u\p> F Y');
$modifiedTime = Date::formattedDateTimeFromTimestamp("$modifiedDatestamp", 'g:i A');
$helper->log('<b>Last Modified On: </b>' . $modifiedDate . ' at ' . $modifiedTime);

Expand Down
26 changes: 22 additions & 4 deletions src/PhpSpreadsheet/Reader/Ods/FormulaTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@

class FormulaTranslator
{
public static function convertToExcelAddressValue(string $openOfficeAddress): string
private static function replaceQuotedPeriod(string $value): string
{
$excelAddress = $openOfficeAddress;
$value2 = '';
$quoted = false;
foreach (mb_str_split($value, 1, 'UTF-8') as $char) {
if ($char === "'") {
$quoted = !$quoted;
} elseif ($char === '.' && $quoted) {
$char = "\u{fffe}";
}
$value2 .= $char;
}

return $value2;
}

public static function convertToExcelAddressValue(string $openOfficeAddress): string
{
// Cell range 3-d reference
// As we don't support 3-d ranges, we're just going to take a quick and dirty approach
// and assume that the second worksheet reference is the same as the first
Expand All @@ -20,15 +34,17 @@ public static function convertToExcelAddressValue(string $openOfficeAddress): st
'/\$?([^\.]+)\.([^\.]+)/miu', // Cell reference in another sheet
'/\.([^\.]+):\.([^\.]+)/miu', // Cell range reference
'/\.([^\.]+)/miu', // Simple cell reference
'/\\x{FFFE}/miu', // restore quoted periods
],
[
'$1!$2:$4',
'$1!$2:$3',
'$1!$2',
'$1:$2',
'$1',
'.',
],
$excelAddress
self::replaceQuotedPeriod($openOfficeAddress)
);

return $excelAddress;
Expand All @@ -52,14 +68,16 @@ public static function convertToExcelFormulaValue(string $openOfficeFormula): st
'/\[\$?([^\.]+)\.([^\.]+)\]/miu', // Cell reference in another sheet
'/\[\.([^\.]+):\.([^\.]+)\]/miu', // Cell range reference
'/\[\.([^\.]+)\]/miu', // Simple cell reference
'/\\x{FFFE}/miu', // restore quoted periods
],
[
'$1!$2:$3',
'$1!$2',
'$1:$2',
'$1',
'.',
],
$value
self::replaceQuotedPeriod($value)
);
// Convert references to defined names/formulae
$value = str_replace('$$', '', $value);
Expand Down
Loading

0 comments on commit 89b30eb

Please sign in to comment.