Commit Graph

4614 Commits

Author SHA1 Message Date
oleibman 60d49eca1c Merge branch 'master' into issue3557 2024-05-30 10:11:18 -07:00
oleibman 52743f9e1b Update CHANGELOG.md 2024-05-30 10:08:51 -07:00
oleibman 4be300865c Writer Mpdf and Tcpdf Borders on Merged Cells
Fix #3557. Borders around merged cells are not handled correctly for Mpdf. Although a perfectly acceptable workaround is suggested in the issue, it would be better if things just worked without the workaround. Html and Dompdf work with the existing code. As it turns out, Tcpdf does not work, but for a different reason than Mpdf.

Mpdf was not working because Mpdf does not honor the `!important` attribute in Css. We can get it working almost perfectly by suppressing `border*:none`; the exception is fairly Byzantine, and I'll be glad to discuss the matter should anyone report a problem with it. At any rate, it's not working now in the exception case, so we won't be any worse off.

Tcpdf was not working because the merging of attributes happened only when `useInlineCss` was not being used, but Tcpdf does use it. Merging of border attributes is now added for useInlineCss.
2024-05-27 16:38:04 -07:00
oleibman 68218c175d Merge pull request #4033 from oleibman/condxlsborder
Xls Conditional Border
2024-05-26 01:53:12 +00:00
oleibman d0c49cd666 Merge branch 'master' into condxlsborder 2024-05-25 18:46:13 -07:00
oleibman 8e87f554b1 Merge pull request #4035 from oleibman/issue3982a
Xlsx Reader Optionally Ignore Rows With No Cells
2024-05-25 13:45:54 +00:00
oleibman 75d630cd0e Update CHANGELOG.md 2024-05-25 06:42:38 -07:00
oleibman 7b25b18a8b Merge pull request #4040 from oleibman/issue4036
Csv Reader Allow Use of mimetype=text/html Files Without Extension
2024-05-25 04:23:56 +00:00
oleibman 72f53de761 Update CHANGELOG.md 2024-05-24 21:18:51 -07:00
oleibman a51d3541c0 Php 8.4 Change Affects Test
mime_content_type will recognize files as text/csv rather than text/html.
2024-05-24 21:00:25 -07:00
oleibman 7ce0184f8e Don't Interfere with SelectedCells And Other Changes
Xls Reader processing Conditionals interferes with the previously established SelectedCells. Make sure that value is restored.

StopIfTrue should always be set for Xls spreadsheet.

Set NoFormatSet to true unless any of Font, Fill, or Borders is specified in Conditional Style.

In my notes for PR #3372, I mentioned that I could not include some Xls tests because of errors in the software at that time. This PR fixes those errors, so I am adding the missing test, and making the equivalent Xlsx test more comprehensive.
2024-05-24 07:58:36 -07:00
oleibman 66415974a5 Merge pull request #4041 from Maikuolan/patch-1
Fix typo.
2024-05-23 13:32:13 +00:00
Caleb Mazalevskis 4dd7000647 Fix typo. 2024-05-23 10:58:17 +08:00
oleibman 2833ddc22d Csv Reader Allow Use of mimetype=text/html Files Without Extension
Fix #4036. The issue was originally reported as #564 (and #811) and fixed for the most part, but this is a variation that was not covered by the original. Cells with html fragments can cause `mime_content_type` to identify the file as `text\html`. Original fix was to ignore mime_content_type when file extension is 'csv' or 'tsv'. However, if the file does not have one of those extensions, it will be rejected by Csv Reader as invalid mimetype. This PR adds text\html to the list of valid mimetypes.

I imagine that this type of problem might occur for other mimetypes. If any of those are reported in future, it might be better to just add a "suppress mimetype" check option, rather than extending the list forever. Html is unusual in that its rules are so lax, which is why it seems appropriate to add it here.

Note that IOFactory may still identify a file as Html even when intended as Csv. The sample associated with this issue does not fall into this category, but one of the unit tests on this ticket does. The file will still be read correctly by Csv Reader, but IOFactory load may cause it to use Html Reader instead.
2024-05-22 08:24:06 -07:00
oleibman 0c2708b1c6 Xlsx Reader Optionally Ignore Rows With No Cells
Fix #3982. A number of issues submitted about Xlsx read performance have a common theme, namely that row 1,048,576 and a few rows before it are defined in the worksheet Xml with no cells attached to them. These might be the work of a third party product. While these extraneous rows do not cause any problems for the cells that are actually used on the worksheet, they can lead to excessive memory use. This PR provides an option for the application to ignore rows with no cells when loading.

Recent changes to the load logic had already made a significant difference to memory consumption and load time. For the spreadsheet attached to issue 3982, which had caused out-of-memory errors on the user's system, peak memory usage was already reduced to 40-odd MB. With the new option, this is drastically reduced again, to just over 9MB. Specifying the new option is very easy:
```php
$reader->setIgnoreRowsWithNoCells(true);
```
Note that there are cases where you might not want this (non-default) behavior. For example, if you set a row height on a row with no cells, the height would be lost with this option. Unfortunately, the extraneous row definitions in the problematic spreadsheets claim to have a custom height, so I can't just use "no custom row styles" as an additional filter.
2024-05-21 19:16:08 -07:00
oleibman 313dcc537b Scrutinizer Identified Some Dead Code 2024-05-21 01:38:32 -07:00
oleibman a6e992671c Xls Conditional Border
Xls Writer Conditional Border had been creating corrupt spreadsheets. This was mainly because a pack statement that should have specified `V` instead specified `v`. Even changing that, the logic was still slightly wrong on write, and missing altogether on read. This PR corrects the write problems and adds the missing read code. It also adds italic and strikethrough support for Xls Writer Conditional Font italic and strikethrough (read code was already in place). With this, Xls Conditional Writer is completely supported except for NumberFormat. Xls does support that, but I cannot figure out how from the available documentation.
2024-05-21 01:04:07 -07:00
oleibman 2ed696f0a2 Merge pull request #4030 from oleibman/condxls
Xls Conditional Format Improvements
2024-05-19 15:36:44 +00:00
oleibman 623efc0211 Update CHANGELOG.md 2024-05-19 08:33:40 -07:00
oleibman 1a187d689b Merge branch 'master' into condxls 2024-05-19 08:15:10 -07:00
oleibman f2a934ae6d Merge pull request #4027 from oleibman/issue4025
Do Not Output Alignment and Protection for Conditional Formats
2024-05-19 15:07:44 +00:00
oleibman f5c1e8796c Merge pull request #4031 from oleibman/powernullarg
POWER Needs to Accept NULL Args
2024-05-16 23:30:15 +00:00
oleibman 989a44d001 Update CHANGELOG.md 2024-05-16 16:26:53 -07:00
oleibman 26d58b4fde Merge branch 'master' into powernullarg 2024-05-16 14:25:03 -07:00
oleibman 1314f82408 Merge pull request #4029 from SchmidtClaudia/issue4028
Incorrect reader used for CSV files with BOM #4028
2024-05-16 19:00:19 +00:00
oleibman f8d994b6e7 POWER Needs to Accept NULL Args
Investigating issue #1622, I found that its extremely complicated formula, which had been leading to an incorrect result, now led to an exception. I am able to fix the exception; unfortunately, I am no closer to resolving the original issue. So I'll apply the baby step while continuing to investigate. Function POWER had changed from untyped args to a defined set of types. The set of types was determined according to the doc block, but that was incomplete - it had neglected to include `null` and `bool`. This PR corrects the function prototype and the doc block, and adds the missing tests for those conditions.
2024-05-16 00:25:47 -07:00
Claudia Schmidt 8091396b52 check HTML syntax on files starting with a BOM 2024-05-16 07:52:41 +02:00
oleibman 5763de4c44 Scrutinizer Recommendation 2024-05-15 19:29:09 -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
oleibman 40adbfe2ff Remove 2 Unneeded Statements 2024-05-13 18:01:21 -07:00
oleibman fe2fc36063 Do Not Output Alignment and Protection for Conditional Formats
Fix #4025. With Conditional Formatting, Excel can change Font, Fill, Borders, and NumberFormat. It does not support Alignment nor Protection, at least not natively. This PR removes all code supporting Conditional Alignment or Protection from Xlsx and Xls Writer. Attached to the issue report is a spreadsheet where a conditionally formatted merged cell shows its value twice when Alignment is included with the Conditional Style; it is fixed by this PR. It is not entirely certain which particular combination of CF, Alignment, Merge, AutoFilter, and right-to-left sheet alignment trigger this problem. I am sure that it shows up for Vertical Alignment Center, and I am sure that Xls Writer (which is somewhat buggy anyhow regarding CF support - see issue #3403) has the same problem. The now-unused Xls code is commented out rather than deleted, for documentation purposes.
2024-05-13 17:26:51 -07:00
Adrien Crivelli 563de5f3da Merge pull request #4024 from PHPOffice/php81
Updates dependencies
2024-05-11 07:39:28 +00:00
Adrien Crivelli ab4e834777 Updates dependencies 2024-05-11 14:13:29 +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
Adrien Crivelli dbed77bd3a 2.1.0 2.1.0 2024-05-11 11:17:56 +07:00
oleibman 791c8cf9a5 Merge pull request #4019 from oleibman/issue3995
Html Reader Non-UTF8 Charsets
2024-05-10 06:28:21 +00:00
oleibman bdcbc0481b Update reading-and-writing-to-file.md 2024-05-09 23:21:26 -07:00
oleibman f8e31b367b Update CHANGELOG.md 2024-05-09 23:07:12 -07:00
oleibman 4577f615c4 Merge branch 'master' into issue3995 2024-05-09 22:49:11 -07:00
oleibman 148165cbe9 Make New Function Static 2024-05-08 23:37:13 -07:00
oleibman d38b7cb35f Merge pull request #4016 from oleibman/stan9a
Better Definitions for Mixed Parameters and Values Part 1 of Many
2024-05-09 06:28:54 +00:00
oleibman b2befb4426 Correct Wrong-Case Directory Name 2024-05-06 16:50:02 -07:00
oleibman 09c9a310a0 Html Reader Non-UTF8 Charsets
Fix #3995. Fix #866. Fix #1681. Php DOM loadhtml defaults to character set ISO-8859-1, but our data is UTF-8. So Html Reader alters its html so that loadhtml will not misinterpret characters outside the ASCII range. This works for UTF-8, but breaks other charsets. However, loadhtml uses the correct non-default charset when charset is specified in a meta tag, or when the html starts with a BOM. So, it is sufficient for us to alter the non-ASCII characters only when (a) the data does not start with a BOM, and (b) there is no charset tag.

This will allow us to use:
- UTF-8 files or snippets without BOM, with or without charset
- UTF-8 files with BOM (charset should not be specified and will be ignored if it is)
- UTF-16 files with BOM (charset should not be specified and will be ignored if it is)
- all charsets which are ASCII-compatible for 0x00-0x7f when the charset is declared. This applies to ASCII itself, many Windows and Mac charsets, all of ISO-8859, and most CJK and other-language-specific charsets.

We cannot use:
- UTF-16BE or UTF-16LE declared in a meta tag
- UTF-32, with or without a BOM (browser recommendation is to not support UTF-32, and most browsers do not support it)
- unknown (to loadhtml) or non-ASCII-compatible charsets (EBCDIC?)

I will note that the way I detect the `charset` attribute is imperfect (e.g. might find it in text rather than a meta tag). I think we'd need to write a browser to get it perfect. Anyhow, it is about the same as XmlScanner's attempt to find the `encoding` attribute, and, if it's good enough there, it ought to be good enough here.
2024-05-06 16:43:23 -07:00
oleibman 8d5577a3c4 Improved Test for ConvertUOM
Scrutinizer balked at quotes around key 'Unit Name'; no reason not to use 'UnitName' instead.

Having done that, several ConvertUOM tests seemed a little unconvincing. Replaced them with improved versions.
2024-05-05 06:14:28 -07:00
oleibman 64f354eb6e Better Definitions for Mixed Parameters and Values Part 1 of Many
Improve documentation within program by making explicit what types of values are allowed for variables described as "mixed". In order to avoid broken functionality, this is done mainly through doc-blocks. This will get us closer to Phpstan Level 9, but many changes will be needed before we can consider that.

Executable code change is to add 2 new methods to Cell - `getValueString` and `getCalculatedValueString`, which are the same as the methods without the String suffix, except that they always return a string result. These are invoked at several places in the code where it makes sense, in particular by Writer code.
2024-05-05 04:37:46 -07:00
oleibman c56a58358e Merge pull request #4006 from oleibman/issue4004
RTL Text Alignment in Xlsx Comment
2024-05-05 11:17:55 +00:00
oleibman 5d1d8671a6 Update CHANGELOG.md 2024-05-05 04:14:24 -07:00
oleibman 4a7fa143f7 Merge pull request #4007 from oleibman/issue4001
Xml Reader Rich Text
2024-05-05 04:26:34 +00:00
oleibman d2a69aec9d Update CHANGELOG.md 2024-05-04 21:13:31 -07:00
oleibman db602bde89 Merge branch 'master' into issue4001 2024-05-04 21:05:15 -07:00