Commit Graph

825 Commits

Author SHA1 Message Date
oleibman ef440dd714 Merge commit from fork 2026-11-01 01:23:38 -07:00
oleibman a845ef2427 Merge commit from fork 2026-10-31 17:03:50 -07:00
oleibman 4ecc20fc05 Merge branch 'master' into fix-branch-pruning-nested-if-condition 2026-10-18 19:25:53 -07:00
oleibman 98ba31713d Merge branch 'master' into wmf 2026-10-18 19:14:23 -07:00
oleibman 8a60a5df51 Merge branch 'master' into fix-right-longer-than-text 2026-10-17 01:21:59 -07:00
oleibman f375a76fb3 Merge branch 'master' into document-language 2026-10-16 13:18:00 -07:00
oleibman 26c227037f Merge pull request #5037 from dkulyk/drawing-decorative
Xlsx, Ods and Html Reader and Writer : Decorative images
2026-10-16 19:59:38 +00:00
HawkForge a7dbf35f62 Fix branch pruning for IF nested in the condition of a pruned IF
When an IF sits in the condition of another IF, BranchPruner only
looked at the immediately enclosing IF to decide which branch the
condition tokens depend on. If that enclosing IF was itself still in
its condition, nothing was recorded, so the link to an outer IF whose
branch is being pruned was lost. Those tokens were then evaluated and
left on the stack while the rest of the branch was pruned, and the
calculation ended with "internal error".

Walk up the stack of enclosing IFs to the closest one whose then or
else branch contains the nested IF instead.

Fixes #3790
Fixes #3755
2026-10-16 20:36:20 +06:00
Progi1984 9d09ae0c31 Support for Windows Metafiles images (WMF, EMF and EMF+) 2026-10-16 07:02:20 +02:00
oleibman e59617c899 Another Test 2026-10-12 20:32:30 -07:00
oleibman 85606d69df Fix Numeric String Comparisons 2026-10-12 18:51:07 -07:00
oleibman e95a97b6f6 Merge branch 'master' into fix-comparison-type-ordering 2026-10-12 14:33:00 -07:00
oleibman 68645cbf34 Add Some Tests 2026-10-12 11:55:46 -07:00
oleibman 09a318952c Merge branch 'master' into fix-countif-boolean-criterion 2026-10-12 10:14:11 -07:00
Dmytro Kulyk b88a7eb3c3 Xlsx and Ods Reader and Writer : Document language
Properties gains a language (a BCP 47 tag), written as dc:language to
Xlsx core.xml and Ods meta.xml and read back from both. Screen readers
and spell checkers use it to pick the voice and the dictionary.

LibreOffice ignores dc:language for the text and keeps a spreadsheet's
language on the default cell style, so the Ods writer puts it there as
LibreOffice does: in the Western, Asian or complex slot by script, with
style:rfc-language-tag for a tag that fo:language and fo:country cannot
hold. The Ods reader falls back to that style when meta.xml has no
dc:language, as in the files LibreOffice saves.
2026-10-11 17:34:46 +03:00
Dmytro Kulyk 98f938fbe6 Xlsx and Ods Reader and Writer : Decorative images
An image that only decorates had no way to say so, and was tagged in a
PDF as a figure without alternative text. Excel and LibreOffice mark it
decorative, and LibreOffice leaves it out of a tagged PDF as an artifact.

BaseDrawing::setDecorative() is written and read in the forms Excel and
LibreOffice use: in Xlsx, adec:decorative in an extension of the image's
cNvPr; in Ods, loext:decorative in the frame's graphic style. The Ods
writer now defines the graphic style its frames named but never wrote.
2026-10-11 17:34:44 +03:00
oleibman c04c2e56b9 Merge branch 'master' into issue5032 2026-10-09 12:05:36 -07:00
oleibman 845d708486 Merge pull request #5005 from guy-black-box/fix-min-max-literal-text
MIN and MAX: count logical values and numeric text typed as arguments, error on other text
2026-10-09 17:51:11 +00:00
oleibman b3511404e0 Merge pull request #5043 from oleibman/realpath
File::realpath should not issue file_exists
2026-10-08 06:59:14 +00:00
kevin9327 d767ea2336 RIGHT: return all of the text when asked for more characters than it has
RIGHT("abc",5) returned "bc" because the start offset went negative and
mb_substr then counted it from the end of the string. Excel returns the
whole text when num_chars is greater than its length, so clamp the offset
at 0.
2026-10-05 12:32:24 +09:00
oleibman 2527575636 Bounded Ranges on Missing Sheet
@dkulyk noticed a case which wasn't handled properly. I believe the fix works for everything ... except `COLUMNS` and `ROWS`, where Excel seems to ignore the sheet, and I just can't figure out how to do it.
2026-10-04 20:24:47 -07:00
oleibman 5b5b12647e File::realpath should not issue file_exists
Fix #5042. `Shared\File::realpath` is used to normalize file name references in a zip file. It can be used for non-zip file names as well, but zip members is its primary use, and `file_exists` does not work with zip file members. Such usage leads to the issue to which this PR is linked, and there have been other instances in past. In particular, issue #3553 was addressed by editing it out a leading slash in such references; it is not needed, and neither Excel nor PhpSpreadsheet generate one, but it's legal. The fix for 3553 addressed only loading a spreadsheet; but `listWorksheetInfo` and `listWorksheetNames` are subject to the same problem, which is this issue.

The normalization that `realpath` does is already built into `File::realpath` using a well-documented algorithm. So neither `filepath` nor `file_exists` is needed there, and they are removed. There are other problems with the current implementation. It looks only for Unix, not Windows, file separators. And a very peculiar problem arises when the zip entry name matches a file path in the current working directory. These problems all go away with this PR.

It is very likely that some manipulation of the zip entry names can be removed entirely from `Reader\Xlsx`. I may look into this in future, but I'm not going looking for trouble now. The fix for 3553 remains in place, even though no changes are made to match it in `listWorksheet...`, so, chances are the 3553 change could be dropped. As I say, maybe some day.
2026-10-04 16:16:38 -07:00
oleibman ad62b91558 Merge pull request #5023 from dkulyk/ods-table
Ods Reader and Writer : Tables as named database ranges
2026-10-04 00:05:01 +00:00
oleibman b67630b614 Merge pull request #5018 from dkulyk/ods-style-hyperlink
Ods Reader : Read the hyperlink LibreOffice keeps in a cell style
2026-10-03 23:47:05 +00:00
oleibman ebfea1db9b Merge pull request #5016 from dkulyk/ods-sheet-rtl
Ods Reader and Writer : Keep the direction of a right-to-left sheet
2026-10-03 23:39:00 +00:00
oleibman 2c6277cacf Merge branch 'master' into ods-table 2026-10-03 07:35:46 -07:00
oleibman ab358c7da9 Merge branch 'master' into feature-box-whisker-chart 2026-10-01 22:04:01 -07:00
Dmytro Kulyk faa841582e Ods Reader and Writer : Tables as named database ranges
The Ods Writer skipped every Worksheet\Table. LibreOffice keeps a table
as a named table:database-range, and from its header row it tags the
header cells of an exported PDF as /TH /Scope /Column (LO master).

The writer now writes one per table, with contains-header and the filter
buttons, after the named expressions as the schema orders them; a table
with no name gets one no other table has. The reader reads a named
database range back as a table and, as LibreOffice does, drops one whose
name is taken or cannot be a table. LibreOffice's anonymous ranges stay
a sheet filter, which now lands on the sheet its address names instead
of the last sheet; a range of a sheet that was not loaded is skipped.
2026-09-30 12:26:43 +03:00
Dmytro Kulyk c6f1560b2e Ods Reader : Read the hyperlink LibreOffice keeps in a cell style
LibreOffice writes the link of a cell that is not plain text (a number,
a boolean, a date, a formula) as style:hyperlink and loext:hyperlink in
the style:table-cell-properties of the cell's automatic style, which is
how it saves a Xlsx file with such links as Ods. The reader looked only
for text:a, so those links were lost.

The reader now maps each cell style to its link and uses it when the
cell has no text:a. A cell with no style of its own takes the default
cell style of its column, as LibreOffice does for A1 in the test file.
2026-09-28 10:15:28 +03:00
oleibman 6d083fdbdd Merge branch 'master' into ods-sheet-rtl 2026-09-27 18:39:52 -07:00
Dmytro Kulyk fc540cb412 Ods Reader and Writer : Keep the direction of a right-to-left sheet
The Ods Writer wrote no direction for a sheet set right to left, so it
opened left to right in LibreOffice. The Ods Reader did not read the
direction either, so a right-to-left sheet saved by LibreOffice came back
left to right.

The Writer now puts style:writing-mode="rl-tb" in the table properties
of such a sheet, as LibreOffice does, and the Reader reads rl-tb or rl
from the table style next to its visibility.
2026-09-27 14:43:43 +03:00
Dmytro Kulyk 08d3797ed1 Ods Reader and Writer : Use the ODF sheet separator in internal links
The Ods Writer turned sheet://Sheet2!A1 into #Sheet2!A1, keeping the
Excel separator, while ODF and LibreOffice write #Sheet2.A1. The Ods
Reader only swapped the prefix, so a link written by LibreOffice became
sheet://Sheet2.A1, and a later save to Xlsx wrote location="Sheet2.A1",
which does not resolve.

The Writer now writes a dot after the sheet name, quoted or not. The
Reader turns that dot back into "!" when a cell address follows it, and
still accepts "!", which older releases wrote and which LibreOffice keeps
when the address after it also parses as R1C1 (#'My Sheet'!C3). A named
range, with no sheet, stays as it is.
2026-09-27 01:32:24 +03:00
Jonathan Goode 4c8b52d09d Add reader support for Box and Whisker charts 2026-09-25 20:24:49 +01:00
Guy Tomer 45c9bc231d Compare values of different types in Excel's type order 2026-09-25 16:50:04 +03:00
Guy Tomer eb5e9ac4e8 MIN and MAX: count logical values and numeric text typed as arguments, error on other text 2026-09-25 16:49:58 +03:00
Guy Tomer 84c6ad4a49 Match logical values with a "TRUE" or "FALSE" criterion in COUNTIF and friends 2026-09-25 16:49:53 +03:00
oleibman 428a495b6c Merge pull request #4989 from oleibman/badxmldate
Minor Xml Reader Improvements
2026-09-23 01:31:07 +00:00
youzixu 2b018e147e Fix VALUE() treating product text as a date
Excel returns #VALUE! for strings like "5V 2.1A - EU Wall Adaptor",
but DateValue's parser accepted them via date_parse("5V-2-1A").

Fixes #4996
2026-09-18 17:31:01 +08:00
oleibman 2de29384aa Merge commit from fork 2026-09-15 20:36:53 -07:00
oleibman 89f455c133 Merge commit from fork
* Security Patch

* Minor Improvement to `unentity`

* More Unentity Tweaks
2026-09-15 19:03:30 -07:00
oleibman c91bae3fed Minor Xml Reader Improvements
Six years ago, my PR #1557 was merged. It was written mainly to improve code coverage in Xml Reader, but some changes and enhancements were made to the Reader code. I noted in that ticket: "File templates/Excel2003XMLTest.xml, used in some tests, is not
readable by a current version of Excel. I have substituted a new file
excel2003.xml to be used in its place. I have not deleted the original
in case someone in future (possibly me) wants to see what it needs to
make it usable." That time has finally arrived.

Excel could not open the file. LibreOffice could, and did a pretty decent job, but something seemed wrong with how it handled formulas. PhpSpreadsheet could not read it, because a field identified as a date/timestamp was wrong - it specified a time-of-day hour as `288`. I made a copy of the file, changed the invalid hour to something valid. It turns out that was not Excel's problem - it still could not read the file. But, for the first time that I can recall, Excel produced decent diagnostic messages! They were in a location that you can't get to through Windows Explorer, even with "hide system files" turned off. However, you could get to it through Windows Command Prompt. There were 56 problems, all involving formulas (which was probably LibreOffice's problem). The formulas were all of the form:

```
of:=[.B1]+[.C1]
```
Now, XML spreadsheets use RC format rather than A1 format for its cells. The formula above is of a style that LibreOffice uses, but Excel does not understand it. It is looking for something like:

```
ss:Formula="=RC[-6]+RC[-5]
```

Excel2003Xml doesn't understand the formula in the file, but PhpSpreadsheet does. But, before it could do so, we had to eliminate the Exception when we tried to parse the invalid date/time. So, the first order of business was to wrap the Xml Reader date conversion logic in a try/catch. This allowed PhpSpreadsheet to read the file, and then to save it as an Xlsx file. Then we could open the Xlsx file in Excel, and save it as Xml. Voilà. We have converted the unreadable Xml file to a readable one. LibreOffice can also read the new file, and the formulas are now correct. BTW, I have no idea what was intended on sheet "Report Data" cells G17:G29. They all subtract a value from an empty cell, so the result is always negative, and try to format it as a date (which Excel doesn't like for negative numbers). Whatever that problem is, there is no need to fix it at this time.

At this point, a little cleanup was still needed. The Xml file was using some strange named styles, e.g. `Medium Date`. I was able to get a list of these with the google query `excel 2003 ooxml named number formats`. However, the list came only in the AI portion of the response; I could not find a link to anything permanent. So I went with what it showed me.

The earlier PR suggested that handling UTF-16 for this format would be difficult. However, saving the now-usable UTF-8 Xml file as UTF-16 with BOM results in a file which PhpSpreadsheet (and Excel and LibreOffice) can read without any code changes.
2026-09-14 07:39:37 -07:00
oleibman c08522896d Merge pull request #4986 from oleibman/odsloadxml
Throw When Ods Reader Encounters Invalid Xml
2026-09-11 16:33:24 +00:00
oleibman f5818019dd Merge pull request #4975 from n3crosis/feature/add-xlsx-file-encryption
Add Agile XLSX file encryption support
2026-09-10 02:22:51 +00:00
oleibman 5bf5b505a9 Throw When Ods Reader Encounters Invalid Xml
`simplexml_load...` can return false, and callers check for it. `dom->loadXML` can do likewise but, till now, it hasn't been checked. Only user of `dom->loadXML` is Ods Reader. Change it to throw if Xml is invalid.
2026-09-07 23:56:14 -07:00
oleibman 918f32d857 Google Is Messing Up a Test with Redirects
Try github instead.
2026-09-04 10:27:18 -07:00
^^ b624d78289 Add sanitized Agile encryption fixture 2026-08-25 19:09:31 +08:00
oleibman 3518d40436 Merge branch 'master' into fix-betainv-underflow-false-convergence 2026-08-08 23:59:16 -07:00
Vincent Gao 52da37f4a7 Fix gamma-family overflow for large shape parameters
GAMMA.INV silently returned the first bisection midpoint for alpha in
~[143, 171.62] (e.g. GAMMA.INV(0.5, 143, 1) gave 358.0 instead of
142.667) and #NUM! above that, because the Newton-step pdf evaluates
Gamma(a), b**a and value**(a-1) in linear domain, all of which overflow
even though the density itself is a small representable number. The same
pattern breaks the GAMMA.DIST, CHISQ.DIST and F.DIST densities and
GAMMALN, which computed log(Gamma(x)) through Gamma(x).

Evaluate these in log domain via the existing logGamma, and scale the
incomplete-gamma series/continued-fraction iteration cap as O(sqrt(a)),
which both expansions need to converge near x ~ a once the shape is
large (GAMMA.INV drifted from the true quantile above alpha ~5000 and
returned alpha+1 by alpha=10000; same for CHISQ.INV at high df).
2026-08-07 01:14:45 +02:00
Vincent Gao f687d261e8 Fix BETAINV false convergence when the Beta CDF underflows
calculateInverse() treated a CDF value of exactly 0.0 as "the guess is the
root" and collapsed the bracket with $b = $a, ending the search. inverse()
already rejects probability <= 0, so a CDF of 0.0 inside the bisection can
only be a float64 underflow at a guess far below the root - never an exact
hit. It is just an ordinary "guess too low" and belongs in the existing
else branch.

The underflow is reached whenever a probe lands many standard deviations
from the mean, so the search collapses after two or three iterations and
returns whichever midpoint it was holding. BETAINV(0.5, 5000, 5000) gave
0.25, though Beta(a, a) is symmetric and its median is exactly 0.5;
BETAINV(0.5, 20000, 3) gave 0.5 against a true 0.99986. Onset is around
alpha = 1080 for beta = 1, where the closed form 0.5 ** (1 / alpha) is
available to check against.

That test also happened to stop the search for shapes where incompleteBeta
declines to evaluate at all and returns 0 for every x, so inverse() now
rejects alpha + beta above that documented limit up front: the CDF is
identically zero there, so no quantile exists to search for.

Tests cover a shape x probability grid against scipy reference values plus
three checks that need no external oracle: the symmetric median, the
Beta(alpha, 1) closed form, and the BETADIST round trip / mirror identity.
2026-08-05 12:28:05 +02:00
oleibman 3006859ecb Merge pull request #4942 from saifulferoz/feature/pivot-table-read
Feature/pivot table read
2026-08-05 03:22:00 +00:00