A follow-on activity to PR #5061. That PR added scrollbars to the dropdown lists when samples were run in a browser. Earlier changes had broken up a number of categories into multiple entries because the dropdown lists were too long and wound up truncated. With the scrollbars, it makes sense to re-consolidate many of those lists, such as ComplexNumbers, which are all essentially the same test as each other. Some break-ups are retained (e.g. Basic/1/2/3/4/5) because they differ substantially from sample to sample; that's kind of an arbitrary decision, but it will have to do for now. I also renamed some of the members so that like members sort together when listing the directory (e.g. all pivot table samples now start with `pvt`). The sample code is mostly unchanged; only the directory and/or member names are changed.
The download samples were moved to their own new directory, and now represent a complete set of all the write formats that we permit. Studying their code, an improvement for `Helper\Downloader` became evident. It had been used merely to copy an existing file to be downloaded. However, by changing the first parameter of `download` to be either the name of the file directory (the existing usage) *or* a `Writer` object poised to issue `save`, you can use it to download your spreadsheet without having to worry about the headers which the browser requires. It then becomes generally useful beyond being used in samples:
```php
$writer = new WriterType($spreadsheet);
$downloader = new Downloader($writer, 'suggestedFileName.xlsx');
$downloader->download();
```
With setPreCalculateFormulas(false) the formula text was written as the
value of the cell (office:string-value and text:p), and LibreOffice showed
it as the result. The cell now has table:formula alone, as the Xlsx Writer
writes <f> without <v>, so the application that opens the file calculates
it. A hyperlink of the cell is still written.
Ods Reader applied a style only to a cell with content or with a cell
after it, so such a formula cell at the end of its row lost its style;
a cell with a formula now keeps it.
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#3790Fixes#3755
These have made it to the nightly Php8.6 for Windows, though it hasn't yet affected that release on Github Ubuntu.
- A string like `xyz` has historically been treated as if it were `<p>xyz</p>` by `Dom->loadHtml()`. No more - recent changes cause it to be dropped altogether, treating it as an empty string.
- `Dom->loadHtml()` seems to have stopped issuing warning messages altogether, so there is no longer any clue that anything untoward has happened.
- There seem to have been some changes regarding how line endings are generated.
- There are doubtless other differences that I haven't stumbled upon yet.
Documentation on these changes is available at https://gitlab.gnome.org/GNOME/libxml2/-/work_items/211
Php says there's nothing they can do about this. Their recommendation is to move to the new Dom\HTMLDocument class. Which is a fine idea, except that we still need to support Php 8.2 and 8.3, and the new class wasn't introduced until Php 8.4. So this PR kludges up our code a bit to use the existing code for libxml releases before the one where these problems were discovered, and the new class for later releases. I think, or at least hope, that this is safe - I don't think the problematic libxml release will be applied to anything earlier than Php8.6.
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.
ODF 1.4 has draw:decorative in the graphic properties, besides the
loext:decorative LibreOffice writes. The flag is now read even with
readDataOnly, which still loads the drawings: a decorative image read
that way was saved as a figure without alternative text.
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.
The loop at the end of Worksheet::removeColumn() removes the leftover
columns from the highest data column leftwards. After each removal it
computed the column to its left, also after the last one, so when the
last column removed was A it called stringFromColumnIndex(0), which
throws "Invalid column index 0". This happened for removeColumn('A', n)
whenever n reached the highest data column, including a plain
removeColumn('A') on an empty sheet, and left the worksheet
half-updated because ReferenceHelper had already shifted the cells.
Loop over the column index instead, so no column left of A is ever
computed. removeRow() already steps down with an integer and is not
affected.
Fixes#5049
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When removing columns or rows, ReferenceHelper::adjustDataValidations()
only shifted the addresses after the removed columns/rows. It never took
the removed columns/rows themselves out of a validation range. So a
validation that lay only on a removed column/row kept its address and
then applied to the column/row that slid into its place, and a range
that ended on a removed column/row kept its size and covered one extra
column/row.
Ranges are now adjusted like Excel does: the removed columns/rows are
taken out of every part of the sqref, a part left empty is dropped,
and a validation with no parts left is deleted. Whole column (B:C) and
whole row (2:3) ranges are supported. Insertion is unchanged.
Fixes#5047
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
@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.
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.
A chart's frame had no descr and was always named "Chart N", so a chart
written by PhpSpreadsheet had no alternative text: LibreOffice exports
the frame's descr as /Alt of the chart's /Figure in a tagged PDF, and
Excel shows it as the chart's alt text.
Chart::setDescription() is written as descr of the frame, which now also
takes the chart's name, and is read back from all three anchor types.
The reader keeps naming a chart after its part file, which
getChartByName() callers rely on.
Fix#5032. When evaluating formulas, stop iterating a cell range when the sheet on which the range is located does not exist.
While testing, discovered some commented-out tests in `ParseFormulaTest`, having nothing to do with this change, that could now be commented back in.