771 Commits

Author SHA1 Message Date
oleibman 1876d6062f Permit Ignoring 'Misleading Format' Tag
Building on PR #3508 and PR #4393, which allowed ignoring 5 different cell 'errors'. Adding this new one should have been dead easy, but MS, in its own inscrutable way, decided to complicate this by making the xml attribute require its very own namespace, unlike any of its relatives.

There are supposed to be several ways to activate this tag. One is to enter a date in cell A1, then in cell B1 enter the formula `=A1`, and set B1's numeric format to `General`.
2026-06-16 19:45:13 -07:00
oleibman 38f346661b Bug in FIXED Function
Fix #4889. Function was not outputting correct number of decimals when thousands separator was omitted.
2026-05-31 09:26:18 -07:00
oleibman 9019a9c9da Merge commit from fork 2026-04-18 23:43:10 -07:00
oleibman 5d6d7d537f Merge branch 'master' into csvnonutf8 2026-04-05 00:03:05 -07:00
oleibman 162fd2ce5b Add Unit Test 2026-03-27 22:54:55 -07:00
oleibman 38a8330748 More Extendability for CSV Reader
A follow-up to PR #4837. PR #4827, to which I am not necessarily committed, shows that there could be a use case for letting a user perform customized logic to convert a non-UTF8-encoded CSV. In addition, several other CSV Reader properties require the use of static or locale properties, which is somewhat problematic; this PR allows them to be set as instance variables, falling back to static/locale only when unset.
2026-03-27 16:16:45 -07:00
oleibman 686f034e96 Merge pull request #4831 from oleibman/issue4823
Xlsx Writer Support Data URI for Images
2026-03-21 05:57:43 +00:00
oleibman dfab88262a Xlsx Writer Support Data URI for Images
Fix #4823. When writing a spreadsheet to Html, a data Uri can be used if `embedImages` is true. Reading such an Html spreadsheet and attempting to write it to Xlsx results in an Exception. It should be noted that Excel itself cannot open the Html properly; none of the images are present.

The PhpSpreadsheet problem arises not with the inclusion of the image, but rather with attempting to include the appropriate entry in `[ContentTypes].xml`. This PR corrects that problem.

For the record, Xls Writer does not have a problem with this situation. Just to demonstrate that, a parallel test for Xls Writer is added in addition to the new Xlsx Writer test.
2026-03-10 19:52:51 -07:00
oleibman 75680f4612 A Bit More Flexibility
And some more tests.
2026-03-09 14:50:04 -07:00
oleibman 3570cf16d1 More Coverage 2026-03-04 11:02:14 -08:00
oleibman 8fd5535fce Coverage Tweak 2026-03-03 20:42:27 -08:00
oleibman 40f7cd00db Consistent Usage of Column and Row Limits
We have identical constants defined in several places, and use literals in others. We aren't consistent in checking limits. This PR makes the use of the constants in Cell/AddressRange the "official" source, deprecates all other constants, and substitutes the constants wherever literals are used. A number of different edge case tests are added.

During testing, I discovered that `columnIndexFromString` correctly throws an exception for 4-character string, but allows `XFE` through `ZZZ`, all of which are also invalid. There are similar inconsistencies with related routines, and this PR attempts to make them operate consistently. One suprise is that throwing for `row=0` causes serious regression problems, so it continues to be permitted (but the high row limit is enforced).

Further, Reference Helper sometimes dips into negative numbers, resulting in totally unexpected results (-1 affects column Z, -2 column Y, etc.). It is changed to ignore rows and columns outside the limits.
2026-03-03 19:04:11 -08:00
oleibman 015afae320 Ods Reader Style Support (Last) - Column Styles (Partial)
Continuing the work of PR #4810 and PR #4813 and PR #4814. According to the spec for LibreOffice, the xml for both coluns and rows allow a `default-cell-style-name` attribute. However, my testing indicates that using that attribute with a row doesn't result in the results I would expect; furthermore, LibreOffice doesn't seem to use that attribute in association with a row (it does use it for columns). For rows, it fills the unpopulated rows in the cell with a repeated table cell with the appropriate style. These filler cells have been a source of problems for us, and I'm not willing to add them at this time (maybe in future). So, if a style is applied to a row in PhpSpreadsheet, it will be reflected in all cells in that row until `highestDataColumn`, but no further.

Since LibreOffice does support adding a style to a column both in the UI and the Xml, it should be a little easier. But its support is imcomplete as well - when reading a spreadsheet, the UI will apply the style only to the rows that are defined in the xml. Again, this requires filler rows for the rows beyond `highestDataRow`, and, again, I am not willing to add those. However, it is important to process the column style when reading because, unlike the case with rows, the cells which are defined in the column may omit style data altogether if the style matches the column style.

There has till now been no support for `ReadDataOnly` (default false) and `ReadEmptyCells` (default true) for Ods Reader. These are now added. ReadEmptyCells is especially important and it would be sensible to usually set it to false. The reason is that LibreOffice usually supplies a width for all the columns mentioned in its row fillers, and PhpSpreadsheet needs to create ColumnDimensions for each of those as a result, resulting in much larger xml than one would expect when the spreadsheet is saved. This arose when I was testing this change - it has always been the case, but nobody has raised an issue about it. We avoid this problem by ignoring the extra columns for ReadEmptyCells false. But this requires a little redundancy in the code. We need to define styles for an entire column before we define styles for the cells in the column, but we don't need to define column widths beforehand. So, if ReadEmptyCells is false, we need to process the columns for styles, then process the cell data (so that we know what `highDataColumn` is), then process the columns again but this time for widths (ignoring columns beyond highDataColumn). If ReadEmptyCells is true, we can process column styles and widths in a single pass.
2026-02-23 17:22:08 -08:00
oleibman 0c64e18cbd Ods Reader Style Support Part 2 - Alignment, Protection, Default Fill
Continuing the work of PR #4810.

Ods Reader changes still to come
- Default border, alignment, protection
- Font
    - subscript
    - superscript
- Borders (up next)
- Style applied to entire row
- Style applied to entire column
- Parent styles?

Ods Writer changes still to come
- Default border, alignment, protections
- Style applied to entire row
- Style applied to entire column
- Parent styles?
2026-02-18 00:56:28 -08:00
oleibman 5f460e6ba7 Some Corrections
Sample 20_Read_Ods exposed some problems which are now corrected.
2026-02-16 01:19:26 -08:00
oleibman 97f63c801f Edge Case
If no `style:default-style` with `text-properties`, use style `Default` with `text-properties` for default.
2026-02-14 23:19:35 -08:00
oleibman 391462f10f Ods Reader Style Support Part 1 - Fonts and Solid Fill
Fix #2622. Fix #1191 (stale as of 2020 but just reopened). A long overdue addition. Ods Reader has till now not supported any styles (although PR #4806 added some support for number formats). This will be the first of several PRs to rectify this situation.

Ods Reader Changes
- Default font
- Font
    - autoColor
    - bold
    - color
    - italic
    - font-family (name)
    - size
    - underline
- Fill (type=Solid only)
    - startColor

Ods Writer Changes
- Default font
- Font
    - strikethrough (fix #4808)
    - size currently always writes to xml with one decimal point, will now eliminate `.0`

Ods Reader changes still to come
- Default fill, border, alignment, protection
- Font
    - subscript
    - superscript
- Fill
    - types other than Solid
- Alignment
- Borders
- Protection

Ods Writer changes still to come
- Default fill, border, alignment, protections
2026-02-14 16:59:11 -08:00
oleibman 53a72cb18a Slight Improvements for Currencies 2026-02-11 17:15:52 -08:00
oleibman fb55d1b6e4 Ods Writer Support Some Number Formats
Redo of PR #4799 due to failed attempt to resolve merge conflict.

Fix #4798. Partially address #3961. Ods Reader supports very little related to styling. Ods Writer supports many styling details, but has not heretofore supported Number Formatting. 3961 addresses both issues; I created 4798 specifically for the Writer side.

Writing number formats to Excel is pretty simple - you just supply a string and that is used directly in the Xml. Ods is much more complicated - it requires Xml nodes that give a complete description of the styling. For that reason, it is difficult and painstaking to convert from the string that Excel (and PhpSpreadsheet) uses to what Ods requires.

This PR provides code to support almost all the styles defined as constants in Style/NumberFormat. It also allows the user to add code to handle otherwise unhandled styles. New Sample55_DefinedStyles demonstrates the use of all the constant styles, plus the addition of a couple of custom styles. I may be amenable to adding some unsupported styles to the built-in list, but the custom style option will always be around in case I am being slow or unreasonable.

This PR does not fully support Ods Reader handling of styles. However, based on the new Writer output, it will often be able to guess the true type of numeric items and assign an appropriate style for that type. So, for example, if it can identify the field as a date, it will assign a date style. It will not always match the style in the sheet being read, but it is a big advance from just formatting the data as a generic number.
2026-02-10 23:48:49 -08:00
oleibman 6252ff325e Merge branch 'master' into fix/ods-read-filter-repeated-columns 2026-02-10 20:03:51 -08:00
oleibman ff03307cce Merge pull request #4801 from IndrekHaav/css-size
Add support for image CSS size in millimetres
2026-02-11 03:51:37 +00:00
oleibman f79394beb4 Merge pull request #4793 from oleibman/listpix
Option to Whitelist External Images
2026-02-11 03:36:17 +00:00
QDenka b392854c9c Fix ODS reader column misalignment with read filter and number-columns-repeated
When using a read filter with the ODS reader, cells with
table:number-columns-repeated containing data were incorrectly handled.
The read filter was only checked for the first column of a repeated
group - if it didn't pass, the entire group was skipped, even if
other columns within the range should have passed the filter.

This caused column data misalignment where filtered columns would
either be missing or contain data from wrong positions.

The fix ensures that:
1. When the first column of a repeated group fails the filter, the
   reader checks if ANY column in the group passes before skipping
2. During data writing, each repeated column is individually checked
   against the read filter

Fixes PHPOffice/PhpSpreadsheet#4802
2026-02-08 13:54:04 +00:00
Indrek Haav eafca4a3a8 Add unit tests 2026-02-07 00:23:56 +02:00
oleibman 9bd828e25d Strange Behavior of CONCATENATE
Fix #4061. CONCATENATE, which has slightly different behavior than CONCAT, and which MS has deprecated for that reason, behaves in an unexpected way when a cell range is presented to it and the spreadsheet does not allow for array results. This would almost certainly occur only for Legacy spreadsheets, but such is what was presented in the issue. The code is changed so that when an array of cells is presented to CONCATENATE, and RETURN_ARRAY_AS_VALUE is in effect, the array will be treated as if it were wrapped in the SINGLE pseudo-function (which is what Excel does by somewhat mysteriously prefixing the cell range with `@`).

This is a niche case. This one stands out because of its deprecation and replacement function. It is possible that other functions exhibit this behavior. I have made no attempt to identify others. A similar approach can probably be applied if issues are raised for others.
2026-02-01 08:51:39 -08:00
oleibman c9b01653e7 Coverage Tweak 2026-01-31 00:40:47 -08:00
oleibman 50a7552f12 Option to Whitelist External Images
Loading external images from a spreadsheet can subject the caller to security exploits. For those who think they need something between not loading any external images (the default and our strong recommendation) or loading them all unconditionally (the current alternative), a callback can now be provided to indicate whether a specific image is okay to load. We continue to urge caution in using this option.
2026-01-30 22:43:21 -08:00
oleibman e1a72c1631 Remove Redundant Tests 2026-01-18 12:25:17 -08:00
oleibman 002f618416 More Tests and a Sample 2026-01-06 11:50:31 -08:00
Thomas Lallement 059a75880e Merge branch 'master' into drawing-in-cell 2026-01-06 09:38:09 +01:00
oleibman b6524f0640 Merge branch 'master' into issue4766 2026-01-03 18:18:34 -08:00
oleibman e92b538efa Strings That Look Like Huge Floating Point Numbers
Fix #4776. DefaultValueBinder treats strings that look like scientific notation as floats. However, if Php evaluates them as `INF`, this can cause problems for Excel. A one-line change to DefaultValueBinder avoids this situation. Tests are added for DefaultValueBinder, and also for StringValueBinder and AdvancedValueBinder, although those extend DefaultValueBinder and needed no code changes.
2026-01-01 17:50:36 -08:00
oleibman 60a04419cc Rowspan in Html
Fix #1319, which went stale in 2020, and is now reopened. Rowspan is not showing up when saving some spreadsheets as Html. There is some logic concerning property `isSpannedRow` which indicates that this is deliberate, but I have no idea what purpose it serves. It leads directly to this issue, and also adversely affects (in a minor way) some samples (e.g. 17a_Html), where merged cells maintain their text but lose their top and bottom padding. After discarding this logic, the reported problem goes away, the samples look better, and no tests fail. So, whatever its purpose, it wasn't tested for. This PR permanently removes the property, and adds a little additional bulletproofing. A minor accommodation is needed for Tcpdf in one place.

This PR probably deletes more lines from Html Writer than it adds. It would not surprise me if this is one of those unusual cases where Coveralls reports a decrease in coverage despite the fact that all the new code is covered.
2026-01-01 16:34:56 -08:00
Thomas Lallement 23f5052b96 Remove duplicated fixture file 2025-12-31 13:43:58 +01:00
Thomas Lallement 35074f377b Finalize XLSX In-Cell Drawing Writer 2025-12-31 13:07:21 +01:00
Thomas Lallement 67f57394ac Merge branch 'PHPOffice:master' into patch-1 2025-12-31 12:04:31 +01:00
oleibman 84747121a1 Changes to WEBSERVICE
This PR started because the documentation on how to configure an Http client was out of date. However, as I investigated further, I found problems. GuzzleHttp, a client mentioned in the documentation, for example - it probably works fine when executed from a browser, but it does not work for `https:` requests from the Windows command line. See https://github.com/guzzle/guzzle/issues/2601, where a user notes that Guzzle's own program to demonstrate how to use it doesn't work, a result that I can confirm is still true. A linked explanation says that the solution is to explicitly specify a path to a CA bundle. For starters, this is impractical from our perspective. One possible solution is to change a php.ini option which is not needed for any other purpose, and which probably needs to change frequently - a burden on users who follow that route. An alternative solution is to use a method `request` to specify the path to the certificate store; this also will need to change from time to time, and, worse, the only method defined in ClientInterface is `sendRequest`, so using this solution isn't client-agnostic, which is a stated goal of https://github.com/PHPOffice/PhpSpreadsheet/commit/7cb4884b96174eb611621635e6fb603ef54178f7. Additionally, it is not clear why an external interface is needed rather than a call to file_get_contents, used elsewhere in PhpSpreadsheet, and not requiring a path to a certificate store.

I also believe that automatically evaluating WEBSERVICE for any arbitrary argument is not a good idea. I am adding a domain whitelist which the user must populate. For domains not in the whitelist, the calculation will revert to `oldCalculatedValue`, which is good enough for pass-through purposes, which probably encompasses most cases. That is how Excel behaves by default - it disables WEBSERVICE calls when it opens a spreadsheet which contains them. For cases where the user adds a new WEBSERVICE call, there is a choice of whitelisting the domain, or getting the result in some other way and using `setCalculatedValue` to store it.

Finally, when a WEBSERVICE call *is* evaluated, it will now accept a cell-address argument rather than just a literal string as is now the case.
2025-12-19 10:12:50 -08:00
oleibman 591ef9acd9 Implement Rest of T.DIST
Found an algorithm for T.DIST  when third argument is FALSE.
2025-12-16 21:34:59 -08:00
oleibman 5b4d7fcdc8 Partial Implementation of T.DIST
T.DIST takes 3 parameters. When the 3rd parameter, a boolean, is true, we now have code to support the request. We still do not have code to handle the false case.
2025-12-16 17:10:53 -08:00
oleibman 5eb46bd48e Fix Some Functions Related to Student-T Distribution
Fix #4167. That problem was initially reported as a problem with TINV, however, at its root, it was actually a problem with TDIST (which TINV needs to call). Both of these are deprecated by Microsoft in favor of some newer functions. PhpSpreadsheet incorrectly treated T.INV as an alias for TINV, and did not implement T.INV.2T, which actually is an alias for TINV.

To solve this problem, I adapted the Perl CPAN module `Statistics::Disttributions`, written by Michael Kospach around 2003. Unit test results have been manually checked against Excel; a few had to be changed because they were wrong (see the original issue). I believe that all of TDIST, T.DIST.2T, T.DIST.RT, TINV, T.INV, and T.INV.2T now function correctly, at least most of the time. I have not found code or an algorithm that I can use for T.DIST nor for T.TEST, both of which remain unimplemented.
2025-12-15 16:53:30 -08:00
oleibman 09f1a57e53 Merge pull request #4746 from oleibman/issue3255
ListWorksheetInfo Improvements for Xlsx and Ods
2025-12-14 16:12:42 +00:00
oleibman a67339973c Merge pull request #4712 from rpg600/5.1.0-patched
feat: add drawing pass-through support for unsupported elements
2025-12-14 09:36:51 +00:00
oleibman 1daaad2576 Xlsx Reader ListWorksheetInfo Honor readEmptyCells
Fix #3255, another oldie (3+ years). Allow the ability to only count rows and columns with data. To avoid a breaking change, keep present logic unless Reader `readEmptyCells` attribute is set to its non-default value, i.e. `false`. This adds very little overhead, and gives a result that I think many users would prefer.
2025-12-13 20:14:11 -08:00
Reinis Grinbergs 1bb6ae8ae5 Add content types when pass-through 2025-12-13 14:34:14 +01:00
oleibman 73138133cf More Tests for LinearBestFit 2025-12-12 07:43:02 -08:00
Reinis Grinbergs 7267164c41 pass-through media files and relationship 2025-12-12 09:36:58 +01:00
oleibman c1be7a5bb5 Strengthen One Test 2025-12-03 19:33:07 -08:00
oleibman e455f73d91 Merge branch 'master' into issue4724 2025-12-02 19:41:09 -08:00
oleibman 65c0477e88 Edge Case 2025-12-01 22:35:43 -08:00
oleibman 98ca50e9fe Handle Surrogates If Read
It is probably very anal of me to do this. Excel does it. I can't see it happening in the wild.
2025-12-01 16:57:42 -08:00