Commit Graph

2427 Commits

Author SHA1 Message Date
Owen Leibman 752a0a5a6c Scrutinizer Recommendations
Two unneeded assignments in tests, one unused parameter in source code.
2020-06-25 23:11:30 -07:00
Owen Leibman 6080c4561d Improve Coverage for HTML Reader
Reader/Html is now covered except for 1 statement.
There is some coverage of RichText when you know in advance that the
html will expand into a single cell.
It is a tougher nut, one that I have not yet cracked,
to try to handle rich text while converting unkown html to multiple cells.
The original author left this as a TODO, and so for now must I.

It made sense to restructure some of the code. There are some changes.
- Issue #1532 is fixed (links are now saved when using rowspan).
- Colors can now be specified as html color name. To accomplish this,
  Helper/Html function colourNameLookup was changed from protected
  to public, and changed to static.
- Superfluous empty lines were eliminated in a number of places, e.g.
  <ul><li>A</li><li>B</li><li>C</li></ul>
  had formerly caused a wrapped cell to be created with 2 empty lines
  followed by A, B, and C on separate lines; it will now just have the
  3 A/B/C lines, which seems like a more sensible interpretation.
- Img alt tag, which had been cast to float, is now used as a string.

Private member "encoding" is not used. Functions getEncoding and setEncoding
have therefore been marked deprecated. In fact, I was unable to get
SecurityScanner to pass *any* html which is not UTF-8. There are
possibly ways of getting around this (in Reader/Html - I have no
intention of messing with Security Scanner), as can be seen in my
companion pull request for Excel2003 Xml Reader. Doing this would be
easier for ASCII-compatible character sets (like ISO-8859-1),
than for non-compatible charsets (like UTF-16). I am not
convinced that the effort is worth it, but am willing to investigate
further.

I added a number of tests, creating an Html directory, and moving
HtmlTest to that directory.
2020-06-25 22:42:38 -07:00
Mark Baker 10a4a95d67
Handle Ranges formatted as 3-d ranges, as long as the references are both to the same worksheet (#1540) 2020-06-21 14:41:51 +02:00
MarkBaker d57cce9aa9 Update changelog 2020-06-20 20:27:17 +02:00
Dawid Warmuz 859bef1901
Add support for IFS() logical function (#1442)
* Add support for IFS() logical function

* Use Exception as false value in IFS logical function, so it never collides with string in spreadsheet
2020-06-20 18:21:19 +02:00
Christoph Ziegenberg ca506ba87f
Corrected date time detection (#1492)
* Corrected date time detection

German and Swiss ZIP codes (special formats provided in German Excel versions) were detected as date time value, because the regular expression for date time formats falsely matched their formats ("\C\H\-00000" and "\D-00000").
2020-06-20 17:15:38 +02:00
MarkBaker acd2ba01df Updates to changelog 2020-06-19 22:38:31 +02:00
MarkBaker c04d0185d9 Updates to changelog 2020-06-19 22:11:07 +02:00
oleibman b3d30f4cbc
Xls Writer - Correct Timestamp Bug, Improve Coverage (#1493)
* Xls Writer - Correct Timestamp Bug, Improve Coverage

I believe that Xls Writer is 100% covered now.

The Xls Writer sets its timestamp incorrectly. The problem is actually
in Shared/Ole::localDateToOLE, which converts its timestamp using
gmmktime; mktime is correct. If I save a file at 3:00 p.m. in San Francisco,
this bug means the time is actually recorded as 3:00 p.m. UTC.
A consequence of this is that if you use Phpspreadsheet to read the
file and save it as a new Xls, the creation timestamp goes further
and further back in time with each generation (or further forward
if east of Greenwich). One of the tests added confirms that
the creation timestamp is consistent with the start and end times
of the test.

The major change in coverage is adding tests to save GIF and BMP
images, which aren't supported in Xls, but are converted to PNG
in the PhpSpreadsheet code.
2020-06-19 21:08:36 +02:00
Arne Jørgensen a5a0268050
Fix HLOOKUP on single row (#1512)
Fixes a bug when doing a HLOOKUP on a single row.

```php
<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

/**
 * Single row.
 */
$singleRow = "=HLOOKUP(10, {5, 10, 15}, 1, 0)";
$sheet->getCell('A1')->setValue($singleRow);

// Should echo 10, but echos '#N/A' and some PHP notices and warnings.
echo $sheet->getCell('A1')->getCalculatedValue() . PHP_EOL;

/**
 * Multiple rows.
 */
$multipleRows = "=HLOOKUP(10, {5, 10, 15; 20, 25, 30}, 1, 0)";
$sheet->getCell('A2')->setValue($multipleRows);

// Should echo: 10 and also does.
echo $sheet->getCell('A2')->getCalculatedValue() . PHP_EOL;
```

Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2020-06-19 21:06:41 +02:00
oleibman 38fab4e632
Fix for #1505 (#1525)
This problem is the same as #1238, which was resolved by #1239.
For that issue, the fix was to check in one place whether
$this->mapCellXfIndex[$xfIndex] was set before using it.
The sample spreadsheet supplied as a description for this
problem had exactly the same problem in 2 other places in the code.
In addition, there were 7 other places in the code where that
particular item was used unchecked. This fix corrects all 9 locations.
The spreadsheet supplied with the problem is used as the basis
for some new tests, which particularly test column dimensions
and styles, the problems involved in this case.
2020-06-19 21:01:18 +02:00
oleibman 3844186397
Fix for Issue 1495 (#1500)
#1495 reports that ActiveSheet can change when calculation
involves jumping around between sheets.
Save index before calculation, restore after, add test.
2020-06-19 20:57:20 +02:00
Arne Jørgensen 1a44ef9109
Fix MATCH when comparing different numeric types (#1521)
Let MATCH compare numerics of different type (e.g. integers and floats).

```php
<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

// Row: 1, 2, 3, 4, 5. MATCH for 4.6.
$sheet->getCell('A1')->setValue(1);
$sheet->getCell('A2')->setValue(2);
$sheet->getCell('A3')->setValue(3);
$sheet->getCell('A4')->setValue(4);
$sheet->getCell('A5')->setValue(5);

$sheet->getCell('B1')->setValue('=MATCH(4.6, A1:A5, 1)');

// Should echo 4, but echos '#N/A'.
echo $sheet->getCell('B1')->getCalculatedValue() . PHP_EOL;

// Row: 1, 2, 3, 3.8, 5. MATCH for 4.
$sheet->getCell('C1')->setValue(1);
$sheet->getCell('C2')->setValue(2);
$sheet->getCell('C3')->setValue(3);
$sheet->getCell('C4')->setValue(3.8);
$sheet->getCell('C5')->setValue(5);

$sheet->getCell('D1')->setValue('=MATCH(4, C1:C5, 1)');

// Should echo 4, but echos 3.
echo $sheet->getCell('D1')->getCalculatedValue() . PHP_EOL;
```

Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2020-06-19 20:54:04 +02:00
Arne Jørgensen 73c336ac96
Fix exact MATCH on ranges with empty cells (#1520)
Fixes a bug when doing exact match on ranges with empty cells.

```php
<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

// Row: 1, null, 4, null, 8.
$sheet->getCell('A1')->setValue(1);
$sheet->getCell('A3')->setValue(4);
$sheet->getCell('A5')->setValue(8);

$sheet->getCell('B1')->setValue('=MATCH(4, A1:A5, 1)');

// Should echo 3, but echos '#N/A'.
echo $sheet->getCell('B1')->getCalculatedValue() . PHP_EOL;

// Row: 1, null, 4, null, null.
$sheet->getCell('C1')->setValue(1);
$sheet->getCell('C3')->setValue(4);

$sheet->getCell('D1')->setValue('=MATCH(5, C1:C5, 1)');

// Should echo 3, but echos '#N/A'.
echo $sheet->getCell('D1')->getCalculatedValue() . PHP_EOL;
```
2020-06-19 20:51:46 +02:00
oleibman d8b4c3b26e
Fix for #1533 (#1534)
Code assumes that formula whose result starts with # indicates error.
Change to check entire result against error list in Functions.
2020-06-19 20:40:28 +02:00
tyomitch 35c04964cf
#1504: Using non-UTC timezone corrupts dates imported from XML spreadsheet (#1506) 2020-06-19 20:38:06 +02:00
oleibman 262896086a
Improve Coverage for Sylk (#1514)
* Improve Coverage for Sylk

I believe that both BaseReader and Sylk Reader are now 100% covered.

Documentation available for this format is sparse.
It was always incomplete, and in some cases inaccurate.
My goal was to use PhpSpreadsheet to load the test file,
save it as Xlsx, and visually compare the two, then add a test
loaded with assertions. Cell values and calculated values,
and border styles were generally handled pretty well without changes.
Other types of styling were not handled so well. I added a few cells
to exercise some previously uncovered code.

Sylk files must be ASCII. I have deprecated the use of the
setEncoding and getEncoding functions, which had no test cases.
2020-06-19 20:35:44 +02:00
oleibman 73379cdfb1
Improve Coverage for Gnumeric (#1517)
* Improve Coverage for Gnumeric

I believe that both BaseReader and Gnumeric Reader are now 100% covered.

My goal was to use PhpSpreadsheet to load the test file,
save it as Xlsx, and visually compare the two, then add a test
loaded with assertions. Results were generally pretty good,
but there were no tests with assertions. I added a few cells
to exercise some previously uncovered code. Code was extensively
refactored; logic changes are noted below.

Code allowed for specifying document properties in an old format.
I considered removing that, but I found the original spec at
http://www.jfree.org/jworkbook/download/gnumeric-xml.pdf
This allowed me to create an old file, which was not handled
correctly because of namespace differences. The code was corrected
to allow for this difference.

Added support for textRotation.

Mapping of fill types was not correct.

* PHP7.2 Error

One assertion failed under PHP7.2. Apparently there was some change in
the handling of SimpleXMLElement between 7.2 and 7.3. Casting to string
before use eliminates the problem.

* Scrutinizer Recommendations

All minor, solved (hopefully) mostly by casts.

* One Last Scrutinizer Fix

... I hope.
2020-06-19 20:34:02 +02:00
oleibman ce6ac1f040
Fix For #1509 (#1518)
* Fix For #1509

User expected no CSV enclosures after $writer->setEnclosure(''),
which had been changed to be consistent with $reader->setEnclosure('').
Writer will now omit enclosures after code above; no change to Reader.
Tests have been added for this condition.

* Add Option to Write CSV Enclosure Only When Required

Allowing the user to specify no enclosure when writing a CSV can lead to
a situation where PhpSpreadsheet (likewise Excel) will not read the
resulting file as intended, e.g. if any cell contains a delimiter character.
This is demonstrated in new test TestBadReread.
No existing setting will rectify this situation.

A better choice would be to add an option to write the enclosure
only when it is needed, which is what Excel does. The RFC4180 spec at
https://tools.ietf.org/html/rfc4180
states when it is needed - when the cell contains the delimiter,
or the enclosure, or a newline.
New test TestGoodReread demonstrates that the file is read as intended.

The documentation has been updated to describe the new function,
and to change the write example where the enclosure is set to null.

* Scrutinizer Suggestions

3 minor changes, all in tests.
2020-06-19 20:28:57 +02:00
oleibman 82ea1d5596
Fix for #1516 (#1530)
This problem is that ZipStream, in contrast to ZipArchive,
is saving 2 files with the same path. I have opened an issue with
ZipStream, who agree that this appears to be a bug.

For the case in question, PhpSpreadsheet is attempting to save
a file with the same path twice (and unexpectedly succeeding)
because of a clone operation. This fix attempts to rectify the problem
by keeping track of all the paths being saved in the zip file,
and not attempting to save any duplicate paths.

The problem case attempted to save printersettings1.bin twice,
but there are other possible exposures, e.g. by cloning a sheet
with a drawing.The new test cases clone an existing sample which
has both printer settings and drawings.
2020-06-19 20:26:02 +02:00
Mark Baker 12dd92bafe
Resolve utf-8 named ranges in calculation engine (#1522)
* Resolve use of UTF-8 in defined names in the calculation engine
2020-06-13 17:35:29 +02:00
oleibman 360c8d8284
Merge branch 'master' into htmledit 2020-06-09 00:39:52 -07:00
Owen Leibman d563254e59 Resoved merged conflict 2020-06-09 00:34:49 -07:00
Owen Leibman c47b407e39 Different Example for Callback
Replace default gridlines with different style. Usable in PDF
as well as HTML.

Documentation mentioned use of setUseBOM with Html, but that method
does not exist, and there is no real reason to support it.
Removed it from documentation.
2020-06-09 00:22:22 -07:00
Adrien Crivelli 7ab920de5b
Typo 2020-06-03 09:13:52 +09:00
Mark Baker 5c18bb5798
Range operator tests (#1501)
* Improved handling of named ranges, although there are still some issues (names ranges using a union type with an overlap don't handle the overlap twice, which as the MS Excel approach to set overlaps as opposed to the mathematical approach which only applies overlap values once)

* Fix tests that misused space and comma as simple separators in cell ranges
2020-06-02 07:38:35 +02:00
oleibman bbaf03c2ef
Update Html.php
Travis says no need to initialize private class variable to null.
2020-05-31 11:18:47 -07:00
oleibman 48c65cff7f
Update CallbackTest.php
resetEditHtmlCallback was removed per suggestions from PowerKiki
2020-05-31 11:11:18 -07:00
oleibman 39eeef5ec6
Update src/PhpSpreadsheet/Writer/Html.php
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 11:01:14 -07:00
oleibman f42c3ef5a0
Update src/PhpSpreadsheet/Writer/Html.php
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 10:59:52 -07:00
oleibman 68002815ec
Update src/PhpSpreadsheet/Writer/Html.php
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 10:59:10 -07:00
oleibman 32b01148f4
Update src/PhpSpreadsheet/Writer/Html.php
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 10:56:27 -07:00
oleibman 7e87a9f8d8
Update samples/Pdf/21a_Pdf.php
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 10:54:30 -07:00
oleibman 9ba8db761b
Update docs/topics/reading-and-writing-to-file.md
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2020-05-31 10:51:53 -07:00
Reijn d7efe9f671 Delete unnecessary class member 2020-05-31 19:03:19 +03:00
Adrien Crivelli ac7fb4a31d
Generate API doc on master
It seems we can't be both on a tag and on master at the same time
2020-05-31 23:11:40 +09:00
Adrien Crivelli 21bfb5b324
1.13.0
### Added

- Support writing to streams in all writers [#1292](https://github.com/PHPOffice/PhpSpreadsheet/issues/1292)
- Support CSV files with data wrapping a lot of lines [#1468](https://github.com/PHPOffice/PhpSpreadsheet/pull/1468)
- Support protection of worksheet by a specific hash algorithm [#1485](https://github.com/PHPOffice/PhpSpreadsheet/pull/1485)

### Fixed

- Fix Chart samples by updating chart parameter from 0 to DataSeries::EMPTY_AS_GAP [#1448](https://github.com/PHPOffice/PhpSpreadsheet/pull/1448)
- Fix return type in docblock for the Cells::get() [#1398](https://github.com/PHPOffice/PhpSpreadsheet/pull/1398)
- Fix RATE, PRICE, XIRR, and XNPV Functions [#1456](https://github.com/PHPOffice/PhpSpreadsheet/pull/1456)
- Save Excel 2010+ functions properly in XLSX [#1461](https://github.com/PHPOffice/PhpSpreadsheet/pull/1461)
- Several improvements in HTML writer [#1464](https://github.com/PHPOffice/PhpSpreadsheet/pull/1464)
- Fix incorrect behaviour when saving XLSX file with drawings [#1462](https://github.com/PHPOffice/PhpSpreadsheet/pull/1462),
- Fix Crash while trying setting a cell the value "123456\n" [#1476](https://github.com/PHPOffice/PhpSpreadsheet/pull/1481)
- Improved DATEDIF() function and reduced errors for Y and YM units [#1466](https://github.com/PHPOffice/PhpSpreadsheet/pull/1466)
- Stricter typing for mergeCells [#1494](https://github.com/PHPOffice/PhpSpreadsheet/pull/1494)

### Changed

- Drop support for PHP 7.1, according to https://phpspreadsheet.readthedocs.io/en/latest/#php-version-support
- Drop partial migration tool in favor of complete migration via RectorPHP [#1445](https://github.com/PHPOffice/PhpSpreadsheet/issues/1445)
- Limit composer package to `src/` [#1424](https://github.com/PHPOffice/PhpSpreadsheet/pull/1424)
2020-05-31 22:49:28 +09:00
Adrien Crivelli dcf3b9860d
Code highlight in docs for PhpStorm 2020-05-31 22:44:25 +09:00
Adrien Crivelli b9a59660d0
Password and hash are exclusive
As specified in https://docs.microsoft.com/en-us/openspecs/office_standards/ms-xlsx/85f5567f-2599-41ad-ae26-8cfab23ce754
password and hashValue are exlusive and thus should be treated
transparently with a single API in our model.
2020-05-31 22:36:37 +09:00
Reijn 1eaf40be69
Update CHANGELOG.md 2020-05-31 20:29:20 +09:00
Reijn dfa6f77178
Add support protection of worksheet by a specific hash algorithm 2020-05-31 20:29:20 +09:00
Adrien Crivelli c434e9b137
Stricter typing for mergeCells
Closes #1494
2020-05-31 15:58:57 +09:00
Owen Leibman edc411e6dd Add ability to save edited Html/Pdf
We give users the ability to edit Html/Pdf, but it's a little cumbersome
to use the edited Html for an Html file, and difficult to use it
for a Pdf. I believe we could make it fairly painless in both cases
by allowing the user to set a callback to edit the generated Html.
This can be accomplished with fewer than a dozen lines of very simple code.
I think this would be easier than grabbing the Html in pieces,
editing it, and reassembling it. I think it would also be simpler
than an alternative I considered, namely the addition of a new method
(e.g. saveEditedHtml) to each of the Html and Pdf writers.

One edit that users might like to make when editing html is to add
fallback fonts, something that is not currently available in
PhpSpreadsheet, and might be difficult to add. A natural extension to
that idea would be the use of webfonts, something which is guaranteed
difficult to add. See samples/Basic/17b_Html for an example of this.

None of the PDF writers support webfonts yet. That doesn't mean they
won't do so in future, but, for now, samples/Pdf/21a_Pdf is a prosaic
example of something you could do with this callback. In fact, this
opens the door to letting the user replace the entire body with data
of their choosing, effectively allowing PhpSpreadsheet (where you can
set things like paper size and orientation) to be used as a front-end to
the Pdf processor without the user having to be be overly familiar with
the vagaries of the PDF processor. I think this is actually a pretty
nice idea. YMMV. See samples/Basic/21b_Pdf for an example.
2020-05-30 21:27:35 -07:00
Mark Baker 8b2bba9bdb
Range operator tests (#1498)
* Fix intersection operator when working with named ranges
2020-05-29 21:53:28 +02:00
MarkBaker b3b0b49b7c Updated changelog 2020-05-25 21:41:02 +02:00
Alban Duval 7ed96e0be1
Calcualtion - DATEDIF - fix result for Y & YM units (#1466)
Bugfix for negative results and too small results

2000-02-02 => 2001-02-01
 > DATEDIF with Y unit: 0 year (returned -1 before fix)
 > DATEDIF with YM unit: 11 months (returned -1 before fix)
2020-05-25 21:33:48 +02:00
oleibman 79d024fec0
Merge pull request #3 from PHPOffice/master
Sync Up With Base
2020-05-24 22:51:25 -07:00
Adrien Crivelli 5a92a5f6b4
Scrutinizer wait shorter for coverage
Since switching to pcov Travis build are much faster and we don't
need to wait that long
2020-05-25 11:20:08 +09:00
oleibman 5dd7e883c6
Fix Issue 1441 (isDateTime and Formulas) (#1480)
* Fix Issue 1441 (isDateTime and Formulas)

When you have a date-field which is a formula, isDateTime returns false.
https://github.com/PHPOffice/PhpSpreadsheet/issues/1441

Report makes sense; fixed as suggested. Also fixed a few minor
related issues, and added tests so that Shared/Date and Shared/TimeZone
are now completely covered.

Date/setDefaultTimeZone and TimeZone/setTimeZone were not consistent
about what to do in event of failure - return false or throw.
They will now both return false, which is what Date's function
said it would do in its doc block anyhow. Date/validateTimeZone will
continue to throw; it was protected, but was never called outside
Date, so I changed it to private.

TimeZone/getTimeZoneAdjustment checked for 'UST' when it probably
meant 'UTC', and, as it turns out, the check is not even needed.

The most serious problem was that TimeZone/validateTimeZone does not
check the backwards-compatible time zones. The timezone project
aggressively, and very controversially, "demotes" timezones;
such timezones eventually wind up in the PHP backwards-compatible list.
We want to make sure to check that list so that our applications do not
break when this happens.
2020-05-24 20:02:39 +02:00
oleibman 585409a949
Testing - Delete Temp Files When No Longer Needed (#1488)
No code changes. The tests in all of these scripts write to at least
one temporary file, which is then read and not used again. The file
should be deleted to avoid filling up the disk system.
2020-05-24 20:03:07 +09:00