Commit Graph

1328 Commits

Author SHA1 Message Date
oleibman 4a459e0558 Merge branch 'master' into issue3907 2024-02-29 17:05:04 -08:00
oleibman b020c208c2 Merge pull request #3916 from oleibman/issue3909
Incorrect SUMPRODUCT Calculation
2024-02-29 21:09:04 +00:00
Nicholas Ruunu c1d141bea3 Fix issue with prepending zero in percentage
Before it was a bug when flooring negative numbers added to the length of
the number for the sprintf mask.
For example -0.091 becomes -9.1 in percentage, floors to -10 which is going to
increase $wholePartSize by 1 and add a leading zero to the result: -09.1% with
format 0.0%.
This happened for negative ranges where floor will increse the length of
the original number.
2024-02-27 23:31:16 +01:00
oleibman 64bdc6424c Incorrect SUMPRODUCT Calculation
Fix #3909. SUMPRODUCT is mishandling multi-row ranges. In Calculation/Calculation, `checkMatrixOperands` will often resize its operands. When it does so, it needs to recalculate the dimensions of each. This fixes the reported problem.

Likely cause was PR #3260. That ticket noted the poor coverage of the code being replaced. Tests of the problem in this ticket were absent and are now added. Despite this, I note that `resizeMatricesShrink` is virtually uncovered, and `resizeMatricesExpand` has substantial gaps in its coverage. I have covered some, but not all, of the Expand gaps. I am struggling to come up with examples to fill its remaining gaps and those for Shrink. However, I will merge this fix in about a week even if I don't succeed.
2024-02-21 22:32:30 -08:00
oleibman a096fcc77d Formula Misidentifying Text as Cell After Insertion/Deletion
Fix #3907. After row/column insertion/deletion, PhpSpreadsheet updates formulas which include cells which have moved. However, it can mis-identify cell addresses within the formula. Examples:
- `=SUM(A2,'F1 (SETTINGS)'!A1:B1)` It identifes F1 as a cell address.
- `=SUM(A2,'x F1 (SETTINGS)'!A1:B1)` It identifes F1 as a cell address. (This looks the same as the above, but, for technical reasons, it's different.)
- `=SUM(A2,definedname1A1)` It identifes A1 as a cell address.
- Sheet names in formulas are compared case-sensitively, and should be compared insensitively. This can make a difference if the formula includes its own sheet name, e.g. on sheet `Data`, formula `=SUM(DATA!A1:A2)` might have to change, but it will not do so with the existing logic.

The defined name part is fairly straightforward. The regular expressions that identify a cell address just have to be a bit more robust. It was doing a negative look-behind for an alphabetic character or dollar sign; underscore, period, and digits, all of which can be part of a defined name, need to be added to that list.

The other situations need a bit of a kludge, but not one so bad that I'm ashamed of it. The formulas will be altered before analysis so that sheet names are replaced with Unicode FFFD (sheetname does not match current sheet), FFFC (sheetname, enclosed in apostrophes, matches current sheet), and FFFB (sheetname, not enclosed in apostrophes, matches current sheet). This prevents the existing regular expressions from finding a cell address within a sheet name, and makes it easy to restore the original, with or without apostrophes, when the sheet name matches the current sheet and the cell(s) which it qualifies have to be changed.

Tests are added for all the situations mentioned above. No existing tests required changes.
2024-02-21 22:10:58 -08:00
oleibman d0393a2eed Merge pull request #3903 from oleibman/issue3900
Handling of User-supplied Decimal and Thousands Separators
2024-02-22 06:04:20 +00:00
oleibman e1fb68efc1 Handling of User-supplied Decimal and Thousands Separators
Fix #3900. The code to adjust Decimal and Thousands separators to user-specified choices expects to convert periods to commas and vice versa - hard-coded without taking the user specification into account. This is likely to be the only significant use case, however, as the issue demonstrates, it is not the only possibility. In particular, it will mess up Csv output if decimal separator is kept as period, but thousands separator is set to null string. The code is altered to replace period with the user-selected decimal separator, and comma with the user-selected thousands separator. No existing tests broke as a result of this change in behavior.
2024-02-14 21:20:45 -08:00
oleibman 1ac1e7f11f Eliminate Some Phpstan-ignore Annotations
This PR resolves about half the statements which we tell Phpstan to ignore. There will still be 23 such annotations spread over 10 source modules for various reasons (too complicated, suspect PhpSpreadsheet code, one Phpstan bug), plus some deliberate errors in the test suite.
2024-02-08 21:14:14 -08:00
oleibman d620497511 Merge pull request #3893 from oleibman/stanarray2
Phpstan Fixes
2024-02-07 17:44:53 +00:00
oleibman 101a31bc24 Phpstan Fixes
Reduce baseline.neon to a single entry.
2024-02-04 20:26:29 -08:00
oleibman 5266086781 Reorganize Samples Part 2
Further reorganization following on PR #3890.
2024-02-04 10:29:41 -08:00
oleibman b3de003aa5 Reorganize Samples
The samples have become unwieldy when running them from a browser. In particular, the drop-down lists are fixed size with no scrolling, and many of them are now just too large. I have moved all the Calculation samples up a level, and broken several categories (Basic, Chart, DateTime, Engineering, Financial, and Reader) into several pieces.

Convert-Online (now found in the Engineering category) had a number of different problems which are now resolved. It is the only member with any significant code change.
2024-02-03 07:25:29 -08:00
oleibman 84cc3b560f Php-cs-fixer Changes
Its latest update added some new stringencies, resulting in 62 messages. Used `composer fix` to take care of them.
2024-02-01 11:26:22 -08:00
oleibman e1bcab6ca9 IF Empty Arguments
Fix #3875. Even better, fix #2146, which has been open for 2.5 years.

Empty arguments are improperly placed on the stack; in particular, they are added without `onlyIf` and `onlyIfNot` attributes.This results in problems described in 3875.

IF has a somewhat unexpected design. In Excel, `IF(false, valueIfTrue)` evaluates as `false`, but `IF(false, valueIfTrue,)` evaluates as 0. This means that IF empty arguments should be handled in the same manner as MIN/MAX/MINA/MAXA, but you need to be careful to distinguish empty from omitted.

Also note that IF requires 2 operands - `IF(true)` is an error, but `IF(true,)` evaluates to 0.
2024-01-27 07:34:37 -08:00
oleibman 132c374f41 Merge branch 'master' into bit32b 2024-01-22 14:24:42 -08:00
Adrien Crivelli ad9fe0a13b Remove all mixed in param type where reasonable (except Calculcation/) 2024-01-22 22:59:24 +08:00
oleibman 6ecd141b02 Merge branch 'master' into issue3866 2024-01-20 16:15:01 -08:00
oleibman 73ee354d00 Update MissingArgumentsTest.php
Misplaced "middle missing" argument.
2024-01-16 15:45:28 -08:00
oleibman 5cfe66e18f Fixes for 32-bit
I check from time to time. There are a number of problems now, mostly due to the elimination of Php 7.4 and replacement of doc-block typing with explicit Php typing.
- Bitwise functions were particularly affected by PR #3718 and PR #3793.
- Chart/Axis and Writer/Xlsx were amusingly affected by PR #3836, which added a scaling option which included an array indexed by the known allowable factors, one of which is 1 trillion, which cannot be represented as an integer on a 32-bit system. Issue3833Test, introduced by the same PR (and not suffering any errors) was expanded to test this value.
- Some minor changes to Reader/Xls and Shared/OLE/PPS to accommodate hex values which are negative in 32-bit but which Php-32 may wind up casting to large floating point numbers; it is not clear to me why these hadn't shown up as problems previously. Possibly this is the result of changes in the most recent Php versions.
- BitAndTest, BitOrTest, BitXorTest and Shared/DateTest were adversely affected by PR #3859 when arguments and/or expected results too large for a 32-bit integer were supplied.
- ImExpTest required a slightly reduced precision for 32-bit. No idea why this hadn't shown up earlier.
2024-01-16 13:09:57 -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 bcd55ef1d3 Merge branch 'master' into issue3687 2024-01-13 07:48:53 -08:00
oleibman 3b7c1f6205 Merge branch 'master' into issue3863 2024-01-11 23:22:56 -08:00
oleibman 9e89c36c97 Excel Omits Between Operator for Data Validation
Fix #3863. Data Validation default operator is `between`. When Excel writes out a data validation item, it may omit the operator. Xlsx reader will therefore initialize operator to null string. Issue indicates that user wants `between` returned for `getOperator`. A more serious problem is that `isValid` method does not handle this situation correctly. Data Validation is changed to set Operator to the default value if an attempt is made to set it to null string.
2024-01-11 23:03:55 -08:00
oleibman 656efb97bf Merge branch 'master' into issue3847 2024-01-10 09:35:10 -08:00
oleibman 5f232348d7 Advanced Value Binder False Positive Looking for Fractions
Fix #3861. Strings ending in `/` were inappropriately identifed as fractions. Fix regexp accordingly.
2024-01-09 19:29:00 -08:00
oleibman 3eedf9e2f0 Better Typing in Test Members
Change "mixed" declarations to more accurate types in test members; in particular, change those that would be flagged if we were to run Phpstan at level 9 (we currently run level 8). I may or may not follow up with source code (over 700 level-9 problems remain for src), but, as with strict typing, there is no reason to avoid the effort for test members.

It was necessary to update some doc blocks in src to accommodate this change. However, no executable code is touched.
2024-01-05 01:43:50 -08:00
oleibman 77f794cb34 Merge branch 'master' into issue3687 2024-01-04 07:40:39 -08:00
Adrien Crivelli c01abbce09 Merge branch 'master' into powerkiki 2024-01-04 11:51:54 +08:00
oleibman 9c279679aa Use Less Space When Inserting Rows and Columns
Fix #3687. Worksheet methods insertNewRowBefore and insertNewColumnBefore call ReferenceHelper insertNewBefore. That function fills in "missing" cells with null values. However, for boundaries, it uses getHighestRow and getHighestColumn. It should be sufficient to use getHighestDataRow and getHighestDataColumn. When there is a big gap between getHighest... and getHighestData..., this can result in a big increase in memory usage, and in file space when saving the spreadsheet. New test InsertTest demonstrates the problem by populating a worksheet with cells A1:D5 (so highestDataRow is 5), but also setting row 1000 to invisible (so highestRow is 1000).

The major part of the change is in ReferenceHelper::insertNewBefore, which will now use getHighestData... for its boundaries when filling in the missing cells. Changes of less impact are made to duplicateStylesByColumn and duplicateStylesByRow so that cells which don't yet exist are not created unless the style that will be applied is not the workbook default style.

As for reducing the file size, Writer/Xlsx/Worksheet is changed so that cells whose value is null or null-string and which use the workbook default style are not written to the output spreadsheet. This requires some changes to existing test ReadBlankCellsTest; I don't think the difference should matter to the end-user.
2024-01-03 18:03:28 -08:00
Adrien Crivelli c1eafc5336 Cleanup PHPDoc according to PhpStorm 2024-01-03 20:51:53 +08:00
oleibman 04d6b1897d Partial Support of Fill Handles
Fix #3847. Person posing the question calls this behavior "pull formulas", and wants equivalent handling to be available in PhpSpreadsheet. I can do this for formulas in a single cell; I can go horizontal or vertical or (unlike Excel) both. Nevertheless, I call this "partial support" because I cannot think how I can do something similar that Excel does, e.g. putting 2 in cell A1 and 4 in Cell A2, selecting them both and using the fill handle to extend those to rows below, so that cell A5 will contain 10.
2024-01-02 18:42:56 -08:00
oleibman b01031d62b Merge branch 'master' into updatefixer 2024-01-01 21:50:09 -08:00
oleibman d164ad2211 Php-cs-fixer Upgrade
It generates a number of new easily-remedied messages.
2024-01-01 20:21:03 -08:00
oleibman 26b9b68a54 Merge branch 'master' into issue3843 2023-12-31 07:53:41 -08:00
oleibman dbb560a923 Do Not Include Unparsed Loaded Drawings When Drawing is Added
Fix #3843. Spreadsheet XML had a lingering Xml drawing tag despite having no drawings. When a new drawing was added, PhpSpreadsheet became confused about which drawings to keep. This PR ensures that it keeps the new and drops the old.
2023-12-28 22:32:09 -08:00
oleibman f76016f02b Win For Scrutinizer!
Test was miscoded.
2023-12-27 18:32:00 -08:00
oleibman 68dec61e4a Html Reader Tolerate Invalid Sheet Title
There are different rules for Title between Excel and Html, in particular maximum length and which characters are valid. Html Reader can throw an exception because of this difference. This PR allows it to tolerate an invalid title, retaining the default title if the Html suggests an invalid one.
2023-12-27 18:13:55 -08:00
oleibman 5cfb7b3a4c Merge branch 'master' into freezeselected 2023-12-26 06:37:09 -08:00
oleibman 168f9adfc0 Merge branch 'master' into sorttoarray 2023-12-23 07:23:03 -08:00
oleibman 421a15a085 Problems With Panes
These glitches were probably due to PR #3622.
- Excel may not properly identify the selected cell on a sheet if freeze panes is in effect, even though the Xml points to the correct pane and the correct selected cell is specified for that pane.
- Worksheet::calculateColumnWidths may alter activePane.
2023-12-22 20:14:09 -08:00
oleibman 096e193495 Improved Performance for toArray
There are severe inefficiencies in `toArray` (or, to be more precise, `rangeToArray`, which toArray calls). For small ranges, the inefficiencies hardly matter, and, for large ranges, the code was likely to exhaust memory before the execution speed mattered. But, with PR #3834 now merged into the codebase, the memory problem is much lessened, and there is now merit in looking into performance.

The code currently accesses each cell in the range. This PR changes it to access only cells which have been initialized - fewer cells processed, and many fewer function calls for those that are. For ranges which are densely filled, there will be little difference. However, for ranges which are lightly filled (a very common occurrence in issues which are raised for this project), the effect will be staggering. The sample file which accompanied 3834 saw an enormous reduction in memory consumption from 20GB to 32MB when toArray was used on it. The same file still took well over an hour to process even after the merge; after this PR, it is processed in approximately a second.

While testing this change, it became apparent that Collection/Cells does not handle column XFD (highest allowed) correctly. That is corrected and new tests added.
2023-12-20 22:47:10 -08:00
oleibman 34863104b3 Chart Axis Display Units and Logarithmic Scale
Fix #3833. Among the options for chart axes in Excel are the ability to show labels as multiples of specific powers of 10, with or without an explanatory label. The Excel spec seems to indicate that that you can customize the multiples to other values, but I don't see how to do that in Excel, so that can be a project for another day if someone figures out how. The label title can also be styled; that is not part of this PR, but I will look into it in future. For now, this PR supports the use of multiples with or without labels.

The axes can also be displayed on a logarithmic scale (any base between 2 and 1000). This PR supports that.
2023-12-19 22:34:35 -08:00
oleibman 7a4dd2d954 Merge branch 'master' into issue2809 2023-12-18 07:48:37 -08:00
oleibman 03da55cd8f Merge branch 'master' into issue3819 2023-12-16 07:20:22 -08:00
oleibman 5a418ea1fb Recurse Directories Searching for Font File
Fix #2809. User felt font files should be searched recursively. The problem could be overcome merely by specifying a more precise font location. However, user has a point - the file layout on user's system is pretty common, and can be integrated into PhpSpreadsheet code easily. As a bonus, the DocBlock for setTrueTypeFontPath, which the user felt was misleading, doesn't even have to change.
2023-12-15 17:30:08 -08:00
oleibman b6aa45659c Slightly Improved Regex
Use lookahead assertion to find xlfn/xlws only when preceding function name.
2023-12-15 02:21:41 -08:00
oleibman 5b7fce9286 Strip _xlfn. and _xlfs. In Formula Translations
Fix #3819. Excel can add these prefixes (basically invisible to end-user). Formula translation in PhpSpreadsheet fails when dealing with these unexpected prefixes, and, even if it handled it correctly, the unexpected prefixes confuse the users. I have changed to strip those prefixes when translating to a locale. This is probably not perfect, but is almost certainly good enough. I could easily add the same change when translating from a locale to English, but I don't think there's a good use case for that, so am opting not to do so for now.

The documentation mentions `translateFormulaToLocale` and `translateFormulaToEnglish`. Neither of these exist; both names are preceded by an underscore. I have changed the code to match the documentation rather than vice versa, retaining deprecated versions of the underscored routines which merely invoke the non-underscored routines.
2023-12-14 13:29:30 -08:00
oleibman 36b9a6484a Merge branch 'master' into countifs 2023-12-13 16:12:18 -08:00
oleibman b0a776d556 COUNTIFS Does Not Require _xlfn
It was on our list as "introduced in 2019". It was, in fact, available with Excel 2007 (https://support.microsoft.com/en-us/office/excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188#bm3), so does not require a prefix when writing it to a spreadsheet. Brought to my attention with issue #3819, although I'm not sure correcting this will entirely solve the user's problem.
2023-12-13 15:43:42 -08:00
oleibman 0fd7cc339a Merge pull request #3821 from oleibman/issue3820
Clone Worksheet With Table and/or Chart
2023-12-13 16:31:02 +00:00