268 Commits

Author SHA1 Message Date
oleibman 9ab866f409 Ignore Settings::libXmlLoaderOptions
Having addressed several security advisories, one evident *theoretical* problem remains. This is an attempt to future-proof our code against similar vulnerabilities. It all begins with our implementation of libXmlLoaderOptions, which uses as a default LIBXML_DTDLOAD. This unfortunate choice opens us to XXE problems, many recently solved. I do not believe that there is a legitimate use case for allowing this, and will therefore ignore and deprecate that option.

Although this might seem to be a breaking change, it is not. The setting is used only after the Xml has been subject to a security scan, and the security scan throws an exception if it detects the use of `<!DOCTYPE` within the Xml. Therefore, the setting will be effective only on Xml which does not contain that tag, and will consequently have no effect on most Xml. The only exception would be Xml which has been crafted to avoid detection by the security scanner in a manner which has not been disclosed to us. Although we hope that we've now blocked all such avenues, this provides additional protection just in case.

With this change in place, we could relax certain restrictions, e.g. the use of EBCDIC or even UTF-7. For now, these will remain in place. I will need to be convinced that there is a legitimate use case for easing the restrictions before doing so. We might even consider the elimination of the Security Scanner altogether. However, it does allow for early detection, and, in any case, provides a method to correct Xml which most Xml readers would fail but which Excel accepts.

My plan is to merge this within the next few days, and tag a new release immediately after. It will also be backported to all active branches.
2024-11-18 22:28:35 -08:00
oleibman 9fe3d71518 Merge branch 'master' into valuebinder 2024-10-09 17:34:48 -07:00
oleibman 1b64b42481 Add Dynamic valueBinder Property to Spreadsheet and Readers
Fix #1395, a 2020 issue which had been marked stale and is now re-opened. Static valueBinder property of Cell isn't ideal. It would be more flexible to make it a dynamic property of the spreadsheet. Static property will continue to be used, but dynamic property will be used first if it is set. Readers will also be changed to add a valueBinder property which they pass to the spreadsheet; however, it will make a difference only for Csv/Html/Slk, since the other readers use setValueExplicit which ignores valueBinder.

Documentation is updated in several places to note that dynamic property is preferred over static.
2024-10-05 23:59:44 -07:00
Guillaume dd56df2b23 🗑️ Deprecate IReader::SKIP_EMPTY_CELLS
This is an alias to `IGNORE_EMPTY_CELLS` there is no point to have both.
2024-09-10 23:30:13 +02:00
oleibman e1dae99a70 Merge pull request #4141 from oleibman/svbignoreerrors2
String Value Binder Allow Setting "Ignore Number Stored As Text"
2024-08-24 23:46:49 +00:00
oleibman 0152f57e44 String Value Binder Allow Setting "Ignore Number Stored As Text"
When String Value Binder converts a numeric value to text, the resulting spreadsheet will be full of little green triangles to indicate to the end user that something might be wrong. It is unlikely that a spreadsheet created in this manner needs that visual clutter. This PR adds a property and setter (I can't really think of a good use case for a getter) to suppress it. Suppression should arguably be the default, but, for now, I will avoid any BC problems by leaving non-suppression as the default.
2024-08-13 14:36:45 -07:00
murongshaozong ef34a8680a chore: remove repetitive words
Signed-off-by: murongshaozong <netease163@icloud.com>
2024-08-13 15:05:26 +08:00
oleibman e5e6bde299 Update Changelog and Docs Prior to Merge Next Week
This will, I hope, be my last change prior to merge on August 7. PR is fully synced with master (except for this change), and, except for an emergency, I do not intend to merge anything else before this.
2024-08-02 10:48:13 -07:00
oleibman 312cd5a6a0 Merge branch 'master' into atsign 2024-07-23 06:25:08 -07:00
oleibman b00dd47c28 Instance Variable for Array Return Type
Till now we have used a static variable/getter/setter to decide what type of result should be returned when a formula is evaluated and an array is the result. This is messy; it would be much better to use an instance variable instead. We cannot eliminate `setArrayReturnType` and `getArrayReturnType` because that would be a BC break. I am considering whether they should be deprecated. In the meantime, I have added a new instance property `instanceArrayReturnType` with getter and setter methods. The property is initially null, and, if it remains so when needed, the static property will be used instead. However, if it is set, its value will be used.
2024-07-10 09:19:51 -07:00
oleibman f6823c79e8 More Doc Updates 2024-07-06 20:26:15 -07:00
oleibman 98ba95eac1 Update features-cross-reference.md 2024-07-04 20:36:29 -07:00
oleibman 2897c4de33 Missed One Doc Change 2024-07-04 20:18:25 -07:00
oleibman 7d8bec828b Documentation Updates
Mostly in response to issue #3961, which noted some discrepancies, both positive and negative, between documentation and reality concerning ODS support.
2024-07-04 20:06:17 -07:00
oleibman edf7f71e2a Merge branch 'master' into atsign 2024-06-30 00:28:18 -07:00
oleibman e8bb091f3b Merge branch 'master' into pr1415 2024-06-29 19:32:02 -07:00
oleibman 02479de01a CSV Writer Allow Varying Number of Columns
Supersedes PR #1415 by @AndrewMonty, which went stale in May 2020, and which is not directly usable due to changes between now and then. Fix #1414, which also went stale; I will remove the stale status and reopen the issue pending the merging of this PR.

Add an option to CSV Writer so that it writes the cells for a row only through the highest data column used in the row, rather than through the highest data column used in the worksheet.
2024-06-27 00:01:55 -07:00
oleibman ef2b5b9e00 Mostly Docs and Tests
Also support for Xml format.
2024-06-21 21:55:05 -07:00
oleibman 2c9e2e2b43 Spill Operator
Spill operator now works both as trailing `#` and ARRAYANCHOR function. `#` is converted to ARRAYANCHOR when writing. I do not think it is important to convert the other way when reading.

Documentation updates have started, but are a work in progress.

SINGLE function is implemented. I believe it works correctly when referring to a cell, but not when referring to a cell range. No attempt is yet made to convert leading `@` to and from SINGLE; I haven't figured out how to do so without interfering with `@` in structured references.

ISREF has problems. At least one of its tests was wrong, and many of those that were right were so accidentally. The code is changed, quite kludgily, so that almost all the tests are now deliberately correct. One very complicated test is incorrect; for now, I will skip it, and will open an issue when this PR is merged.
2024-06-20 00:43:03 -07:00
Christian Weiske 1c931e2870 Documentation and example for rangeToArrayYieldRows()
Related: https://github.com/PHPOffice/PhpSpreadsheet/pull/3906
2024-06-17 11:29:36 +02:00
oleibman ad2194d737 CONCATENATE Changes, and Csv/Html/Ods Support
The CONCATENATE function has been treated as equivalent to CONCAT. This is not how it is treated in Excel; it is closer to (and probably identical to) the ampersand concatenate operator. The difference manifests itself when any of the arguments is an array (typically a cell range). Code is added to support this difference.

Support for array results is added to Csv Writer, Html Writer, and Ods Reader and Writer. I have not figured out how to get it to work with Xls.
2024-06-14 08:30:18 -07:00
oleibman 0f515eee0b Xls Conditional Format Improvements
While researching another problem, I noticed that font color was not working as expected for Xls Conditional Formats, at least not when a "non-standard" color is used. In such cases, the color might wind up being rendered as black. The reason is as follows. Xls Writer includes a color palette which is dynamically generated from the (non-Conditional) styles used in the workbook. Any colors used in the workbook are indexes to this dynamic palette. However, Conditional colors use a static palette found in class ColorMap to determine the index, so the determination of index will often not find a match, and, if a match is found, it is not necessarily correct. (Also, the ColorMap method was case-sensitive and needs to be insensitive.)

In order to correct this, the `addColor` method in Xls Writer Workbook needs to be accessible to the Conditional logic which is found in Xls Writer Worksheet. This is accomplished by passing the Workbook in the Worksheet's constructor, and changing the method to public, and changing Conditional Font to use this method rather than ColorMap.

The logic for Conditional Fill colors is similarly changed. Although Xls Conditional Fill has appeared to just not work, I was finally able to figure out the problem. Excel Xls Conditional Fill with fill type Solid requires that the fill color be specified as startColor, and that endColor be omitted. Our conditional samples used endColor, and are now changed to use startColor instead; the same is true for our online documentation, and for some tests. Xlsx continues to work as expected, and now Xls does at least some of the time. If the condition is one that Excel Xls does not recognize (e.g. cell contains), it will, of course, not work. A surprising situation that also doesn't work is the use of ISODD or ISEVEN in formulas. Those are "add-in functions" which are handled differently than other functions, and I'm not sure how to support them. I will document this in issue #3403.

Samples 08_Conditional_Formatting(_2) had produced corrupt Xls versions. This turned out to be because the code was using hash codes to avoid having to write out duplicate conditionals; this is often a good idea, but not in this case. Allowing the duplicates fixes the corruption problem.

Conditional Border colors also ought to figure in this change, but the current code does not support Border colors, and I have not yet been able to figure out how to implement it (BIFF format can be very messy to figure out).

With this change, I could delete ColorMap altogether. However, it is a public class with a static public method, so maybe someone is using it for a purpose I'm not familiar with. I will just deprecate it.
2024-05-15 17:41:34 -07:00
Adrien Crivelli 8968062e8d Drop PHP 8.0 support
This is according to our formal, published, policy to only support
EOL PHP after 6 months.

See https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support

Also consolidate documentation in a single place, not in the README,
because it's a pain to maintain almost-duplicated-but-not-really
documentation.
2024-05-11 14:09:30 +07:00
oleibman bdcbc0481b Update reading-and-writing-to-file.md 2024-05-09 23:21:26 -07:00
oleibman e63e8a9bbf Merge pull request #3959 from oleibman/docrector
Update Rector Documentation
2024-03-25 02:22:10 +00:00
oleibman 6208887c12 Update Rector Documentation
Rector no longer supports conversion from PhpExcel (issue #3953). Documentation is updated to suggest using a non-current release of Rector for conversion.
2024-03-24 19:17:22 -07:00
oleibman f64e0ecd79 Merge branch 'master' into issue3951 2024-03-24 17:40:54 -07:00
oleibman 891180e13d Protect Sheet But Allow Sort
Fix #3951. When an Excel sheet is protected, even when sorting is explicitly allowed without a password, sorts are permitted only on "protected ranges" within the sheet. PhpSpreadsheet already supports protected ranges, and only minor tinkering is necessary for that (e.g. the protected range can have, but does not require, a password). The more important part of this change is documenting the far-from-intuitive way that Excel handles this. To that end, documentation is updated, and a new sample is added.

A new class, `Worksheet\ProtectedRange` is added in place of the string array which had been used. `Worksheet::getProtectedCells` is deprecated in favor of the new `Worksheet::getProtectedCellRanges`.
2024-03-20 07:04:24 -07:00
Mark Baker d01575416a Merge pull request #3937 from PHPOffice/Looping_the_Loop
Documentation about Iterating through Cells
2024-03-11 15:24:53 +00:00
Mark Baker a1e1af697c Merge pull request #3936 from PHPOffice/Behind_the_Mask
Documentation about Number Format Masking
2024-03-11 15:17:14 +00:00
Mark Baker 7b55c61552 Merge pull request #3938 from PHPOffice/The_Dating_Game
Documentation about Date Handling
2024-03-11 15:13:54 +00:00
oleibman 5587ca0cd5 Merge branch 'master' into issue3918 2024-03-08 19:14:49 -08:00
MarkBaker 3435faeca5 Documentation about Date Handling 2024-03-07 12:38:38 +01:00
MarkBaker 868f6d4abe Documentation about Iterating through Cells 2024-03-07 12:37:40 +01:00
MarkBaker 790f489fe2 Documentation about Number Format Masking 2024-03-07 12:35:20 +01:00
oleibman d418762a33 Win For Scrutinizer
It pointed out a problem that I would have thought should result in test failure. Code corrected, and documentation updated to describe the unexpected behavior.
2024-02-29 12:18:34 -08:00
Adrien Crivelli c677a2f1c8 Never mention a specific PhpSpreadsheet version in documentation 2024-02-11 14:39:49 +08:00
oleibman 0d6673dd8a Excel Inconsistent Handling of Empty Argument MIN/MAX/MINA/MAXA
Fix #3866. Excel normally treats a missing argument (e.g. `PRODUCT(2,3,)`) as null and ignores it. Not so for MIN/MAX/MINA/MAXA; for those, an empty argument is treated as zero. PhpSpreadsheet is changed to do the same.
2024-01-15 07:56:01 -08:00
oleibman 0cd725d000 Automate Function-by-Name and Function-by-Category Docs (#3818)
* Automate Function-by-Name and Function-by-Category Docs

Examining whether it is possible to analyze the 2 Php scripts in the bin directory even though they lack a .php extension, I found that the docs generated by `generate-document` had not been updated in over a year even though support for a number of functions (e.g. ARRAYTOTEXT) had long ago been implemented. The files generated by the other script `generate-locales` are automatically generated as part of the unit test suite, and I can't see any reason not to do the same for `generate-document`.

It isn't totally clear that the 2 scripts in bin are needed any more now that each has an equivalent in the unit test suite. For now, I'm keeping them, and allowing them to be analyzed by phpcs, php-cs-fixer, and phpstan.

* Reflection Not Required

Remove it from bin scripts and DocumentGeneratorTest.

* Better Html/Css Display for Function Lists

* Redesign Features Cross Reference Doc

It was inaccurate, and pretty much impossible to read in entirety. This version should be easier to read, and to correct. That's important, because there are almost certainly new inaccuracies in this version.

* Add Html to Features Cross-Reference Readers
2023-12-11 07:38:13 -08:00
oleibman 02a6513ec8 Remove byColumnAndRow Examples From Documentation (#3816)
* Remove byColumnAndRow Examples From Documentation

Responding to https://github.com/PHPOffice/PhpSpreadsheet/discussions/2706#discussioncomment-7798739.

* Migration From PHPExcel - Charts

Updated section to recommend use of mitoteam/jpgraph.

* Update accessing-cells.md

Remove 'by coordinate' from headings.
2023-12-09 07:46:50 -08:00
oleibman c5527ba534 Unexpected Namespacing in rels File (#3722)
* Unexpected Namespacing in rels File

Fix #3720. Third-party product created a spreadsheet which PhpSpreadsheet could not read because of unexpected namespacing in workbook.xml.rels.

The file which demonstrated the problem was attached to #3423, however I do not believe it was related to the original problem. Nevertheless, the original issue specifically called out Protection, so I put some Protection tests in the validation test for the fix. In doing so, I found that Style/Protection is particularly confusing. Its properties will often have the value `inherit`, which isn't all that helpful; and, even when the `locked` value is `protected`, the cell won't actually be locked unless the sheet is protected as well. The `hidden` property is even more obscure - it applies only to formulas, and refers to hiding the property on the formula bar, not in the cell. I have added methods `isLocked` and `isHiddenOnFormulaBar` to `Cell`. I corrected the docs to explain this. And, as long as I was looking at the docs, I corrected some examples to use `getHighestDataRow/Column` rather than `getHighestRow/Column`, a frequent problem for users (e.g. #3721).

As a side note, the change to Cell.php is my first use of the nullsafe operator. This is one of many new options available now that we require Php8.0+.

* Minor Simplifications

* Scrutinizer

It's being silly again. In many tests, we test a variable for non-null, then use that variable later and Scrutinizer knows it's not null. Not here. Oh well.

* Add Methods

Test if protected without allocating cell if it doesn't exist.
2023-09-12 19:13:03 -07:00
Adrien Crivelli f131ca30e6 Drop PHP 7.4 support
This is according to our formal, published, policy to only support
EOL PHP after 6 months.

See https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support

Also share the exact same dev deps across all PHP version for GitHub
Actions so runs are faster, much most importantly they are stable and
predictable. And we decide manually when we want to migrate to PHPUnit
10.

Fixes #3634
Closes #3710
2023-09-06 22:51:47 +08:00
Juan Antonio FM 0bc8330b77 Update migration-from-PHPExcel.md (#3646)
added missing composer dep.
2023-07-16 06:48:57 -07:00
jpachta e258918a81 Update reading-files.md (#3607)
Fixed typo in code examples in name of variable `$columnAddress` that was wrongly shortened to `$column`. Long version of the variable name $columnAddress is used in the corresponding samples scripts so now the docs match the samples.
2023-06-07 22:09:12 -07:00
oleibman c998e46a4a Document advancedBorders Parameter for applyFromArray (#3542)
Fix issue #3539.
2023-05-02 05:08:50 -07:00
oleibman 86d2505925 Documentation Updates (#3517)
Fix #3471. Fix #3514. No code changes.
2023-04-10 08:45:14 -07:00
oleibman d6180ad113 Font Themes (#3486)
* Font Themes

It isn't a feature of Excel that I've made any use of, but PR #3476 added better Theme support for colors, and it is relatively easy to add Theme support for Fonts on top of that.

Excel assigns two theme fonts to its spreadsheets, one for Headings (major), and one for Body (minor). If the body theme is Calibri, when you choose a font for a cell in Excel, you can choose 'Calibri (Body)' from the Theme Fonts section at the top of the Font dropdown, or 'Calibri' from the 'All Fonts' section. If you choose the former, the cell will be automatically restyled if you change the Theme Fonts (via Page Layout, Themes, Fonts). The relationship to the theme fonts is recorded in the XML via a `scheme` tag (descending from `font`) whose `val` attribute can be either `major` or `minor`. Accordingly, this PR, in addition to defining the Theme Font properties, adds a `scheme` property, with getter and setter, to Style/Font.

The main benefit of this PR is that you can now load and save a spreadsheet preserving the connections to the Theme Fonts, without having to take any additional action.

A secondary benefit arises from the following difference. Empty cells in Excel will use the spreadsheet's default font name when they are filled in; but, in Google Sheets, they will use the Theme Minor Font name. By setting the `scheme` property in the default style, the resulting spreadsheet will behave the same in both Excel and Google.

I will note that Excel's font themes specify a Latin font, an East Asian font, a Complex Scripts font, and a set of font substitutions for various languages. PhpSpreadsheet will preserve all of these, and allow them to be changed. However, although it is easy to imagine how the non-Latin options might work, I have not yet been able to come up with an example where Excel uses any of them. In particular, if I use a theme font which does not support language X, and I use Language X in a cell bound to the theme, Excel will use a substitution font which does support it, but the font which it uses does not seem to be chosen from the alternatives supplied in the theme.

* Scrutinizer

The sun rises in the east, and Scrutinizer issues more false positives.
2023-03-31 17:12:37 -07:00
Esteban Gehring 27a1c598da update instructions for migration from phpexcel (#3483) 2023-03-25 07:31:59 -07:00
MarkBaker 3240d022d5 Include an example of Date/Time NumberFormat Wizards in the documentation 2023-03-19 06:25:53 +01:00
MarkBaker 202964ee26 Minor update to documentation index 2023-03-09 17:37:50 +01:00