Commit Graph

147 Commits

Author SHA1 Message Date
Zdeněk Drahoš 42fc71f314 Calculation/Statistical :: Add MAXIFS, MINIFS, COUNTIFS and Remove MINIF, MAXIF (#1059)
* #1056 - replace invalid minif/maxif functions by not implemented minifs/maxifs

minif/maxif is not support in Excel, Google Spreadsheets, Libreoffice
https://support.office.com/en-us/article/excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188#bm13

* #1056 - implement minifs/maxifs

Copy-pasted sumifs...
https://github.com/PHPOffice/PhpSpreadsheet/blob/1.8.1/src/PhpSpreadsheet/Calculation/MathTrig.php#L1254

* #1056 - implement countifs

* #1056 - fix code style

composer check
composer fix

* #1056 - update changelog
2019-07-14 12:55:42 +02:00
Mark Baker 0ea97f14e1
Fixes to coupon functions (#1068)
* New Unit Tests for COUPNUM()

* COUPNUM should not return zero when settlement is in the last period

* Additional tests and fixes for COUPNCD() and COUPPCD() functions
2019-07-10 21:22:16 +02:00
Mark Baker d8047b071b
Basic unit test and fix for loading data validations from xlsx file (#1063) 2019-07-08 19:55:14 +02:00
Mark Baker 0e6238c69e
CVE-2019-12331 (#1041)
* Detect doubly-encoded xml to hide XXE attacks
Correct use of LibXml_Disable_Entity_Loader

* New test for double-encoded xml in security scanner
2019-07-01 00:55:25 +02:00
Mark Baker 1e711541f1
Refactoring xlsx reader (#1033)
Start work on breaking up monolithic Reader and Writer classes into dedicated subclasses to make maintenance work easier
2019-06-30 23:42:25 +02:00
Mark Baker 6c25b6f422
Refactor Xlsx Properties Reader code into a separate class (#1001)
* Unit tests for refactoring Spreadsheet properties
* Refactor Xlsx Properties Reader code into a separate class
2019-06-10 16:44:55 +02:00
kraser 906bdc613c Fix failure when parsing xlsx with drawing having double (redefined) … (#945)
* Fix failure when parsing xlsx with drawing having double (redefined) attributes

* Fix failure when parsing xlsx with drawing having double (redefined) attributes
2019-05-30 11:42:00 +02:00
Aleksandr Borovikov 53ac682ba7 Fix #956: Incorrectly handled backslash-escaped space characters within number formats (#957)
Backslash-escaped space characted sometimes not converted to quoted strings, so formatted string contains extra slashes.
2019-05-30 11:37:48 +02:00
AlexPravdin ebc0b56959 Fix #853 when loading and saving XLSX file with empty drawing cause c… (#882)
* Fix #853 when loading and saving XLSX file with empty drawing cause corrupted output file. Store empty drawing as unparsed entity and save it as is when saving the file.

* Fix code style
2019-05-30 10:38:03 +02:00
Harry Gulliford 0b3deeaac5 Add accounting number format style (#974) 2019-05-30 09:18:03 +02:00
Yigit Cukuren cce6e5976f Calculation :: Added switch function (#983) 2019-05-30 09:14:58 +02:00
Fräntz Miccoli 9a208b31d8
Fix a SUMIF warning when having different length of arrays provided as input
Closes #873
2019-05-26 20:58:00 +12:00
Fräntz Miccoli ccebf0f288 Fix VLOOKUP whose return was impacted by order for a $not_exact_match (#854)
* Highlight VLOOKUP bug with a new test

* Remove useless statements + fix VLOOKUP bug

Please not that we have still inconsistencies in Excel (See LOOKUP and
VLOOKUP.php test files)

* Base strtolower on our StringHelper in LookupRef
2019-04-15 21:37:23 +02:00
Fräntz Miccoli 8b589c4ef3 Fix MATCH an error was appearing when comparing strings against 0 (always true) + making a return statement a bit more explicit (#855) 2019-03-06 22:37:06 +01:00
Mark Baker 9b004b1e6a
Ignore escaped enclosures within an enclosure when inferring csv separator (#906) 2019-02-25 23:20:50 +01:00
Patrick Brouwers 1c99f4999c [Feature] Html reader improvements (#884)
* Extract character set, so we can convert to UTF-8 if required

* Set column width and row height when defined on tr/td

* Parse align and valign on td

* Specify number format of cell via html attribute

* Formatting of b, strong, i and em tags

* Inserting image in cell when using img tag in html

* Add applying inline styles: border, fonts, alignment, dimensions

* Add tests for applying inline styles
2019-02-16 23:11:16 +01:00
GreatHumorist 699da09176
Fix time format for duration was incorrect
When using format `[h]:mm` it should convert to the "total hours:minutes"

Closes #666
Fixes #664
Fixes #446
Fixes #342
2019-01-02 13:17:52 +11:00
Adrien Crivelli e8c25c33cd
Fix unit tests for 2019 2019-01-01 17:48:07 +11:00
Fräntz Miccoli 294ba58dde
Exact match in VLOOKUP now returns first match
It was inconsistent with spreadsheet software before.

Closes #809
2018-12-15 17:42:07 +11:00
Fräntz Miccoli db2621c4fe
Add tests for the LOOKUP function
We were performing operations to patch for missing $result_vector
even when one was defined, this was causing bugs on edge cases.

Fixes #796
Closes #816
2018-12-15 16:23:45 +11:00
Mark Baker a5eb64c77f
Matrix (#790)
* Refactor Excel Matrix functions to use external Matrix library rather than JAMA
2018-11-29 22:25:31 +01:00
MarkBaker 41bcf9a21c Support for additional callback in XML Security Scanner 2018-11-25 14:00:35 +01:00
MarkBaker 7a06d71e1c Add UTF-7 XXE Unit test data 2018-11-19 23:22:59 +01:00
Laurent 79d86ef5cc
Csv reader avoid notice when the file is empty
Fixes #337
2018-10-28 14:16:53 +11:00
marcusblevin 98d10475f2
SUMIFS sum values only once
Values were summed multiple times if it matched several conditions
whereas it should only be summed once.

Fixes #704
Fixes #710
2018-10-28 13:09:08 +11:00
Sreten Ilić ed6a3a0148
Support numeric condition in SUMIF, SUMIFS, AVERAGEIF, COUNTIF, MAXIF and MINIF
Fixes #683
Fixes #701
2018-10-28 12:47:53 +11:00
Paul Barton 813855b2b2
Fix CSV delimiter detection on line breaks
The CSV Reader can now correctly ignore line breaks inside
enclosures which allows it to determine the delimiter
correctly.

Fixes #716
Fixes #717
2018-10-21 18:23:55 +11:00
Biser Antonov 2c981e47a1
Added the DAYS() function
https://support.office.com/en-us/article/days-function-57740535-d549-4395-8728-0f07bff0b9df
2018-10-21 15:26:46 +11:00
bayzhanov 08b4456641
Xls file threw exception during open by Xls reader
Ignore some exception in property, if stream is empty

Fixes #402
Fixes #659
2018-10-07 18:49:01 +11:00
Scorty ae9dd13aa0 Skip non numeric value in SUMIF
MS Excel skip non numeric values also. PhpSpreadsheet used to fail on string value with: Warning: A non-numeric value encountered.

Fixes  #618
2018-10-07 17:24:23 +11:00
Timur 50a9bc83ab Sheet title can contain exclamation mark (in formulas)
When extracting sheet title from string reference (like `"Work!sheet1!A1"`), PHP function `explode()` divide this string into three parts: `['Work', 'sheet1', 'A1']`. And then these wrong values are used in formulas, ranges, etc.

This change fix that problem by using special function `Worksheet::extractSheetTitle()`. This function also has been changed to make sure that worksheet title can contain "!" character. So, that function search last position of "!" in reference string and divide it to 2 parts correctly: `['Work!sheet1', 'A1']`.

Fixes #325
Fixes #662
2018-10-03 12:52:51 +09:00
Derek Bonner 01501b6ff2 Remove locale from format string to prevent formatting error (#644)
When a formatting string has a locale in it an error can occur when outputting. For example when the format string with a locale such as `[$-1010409]#,##0.00;-#,##0.00` appears, a value of 9.98 comes back as $9.98. This is because at https://github.com/PHPOffice/PhpSpreadsheet/blob/1.4.0/src/PhpSpreadsheet/Style/NumberFormat.php#L711 the numberFormat regex will match to the zeros inside the locale ([$-1010409]). Attempts to adjust the numberFormat regex caused regressions in other tests. Adding another step to filter out the locale caused no regression.
2018-09-28 21:28:40 +09:00
Mark Baker 1b96c95a44
Add new Complex Number Functions introduced in MS Excel 2013 (#601)
* - Refactored Complex Engineering Functions to use external complex number library
- Added calculation engine support for the new complex number functions that were added in MS Excel 2013
    - IMCOSH()  Returns the hyperbolic cosine of a complex number
    - IMCOT()   Returns the cotangent of a complex number
    - IMCSC()   Returns the cosecant of a complex number
    - IMCSCH()  Returns the hyperbolic cosecant of a complex number
    - IMSEC()   Returns the secant of a complex number
    - IMSECH()  Returns the hyperbolic secant of a complex number
    - IMSINH()  Returns the hyperbolic sine of a complex number
    - IMTAN()   Returns the tangent of a complex number
* Simplified the parseComplex() method in the PhpOffice\PhpSpreadsheet\Calculation\Engineering class, using Complex\Complex; and docblock flagged as deprecated
2018-07-25 14:38:44 +01:00
Mark Baker 67cdee6033
Add new Bitwise Functions introduced in MS Excel 2013 (#603)
* - Added calculation engine support for the new bitwise functions that were added in MS Excel 2013
  - BITAND()     Returns a Bitwise 'And' of two numbers
  - BITOR()      Returns a Bitwise 'Or' of two number
  - BITXOR()     Returns a Bitwise 'Exclusive Or' of two numbers
  - BITLSHIFT()  Returns a number shifted left by a specified number of bits
  - BITRSHIFT()  Returns a number shifted right by a specified number of bits
2018-07-22 22:16:34 +01:00
Mark Baker 9b44cf3418
Add further new Functions introduced in MS Excel 2013 and 2016 (#608)
- Fix ISFORMULA() function to work with a cell reference to another worksheet
 - Added calculation engine support for the new functions that were added in MS Excel 2013 and MS Excel 2016
   - Text Functions
     - CONCAT()     Synonym for CONCATENATE()
     - NUMBERVALUE()  Converts text to a number, in a locale-independent way
     - UNICHAR()    Synonym for CHAR() in PHPSpreadsheet, which has always used UTF-8 internally
     - UNIORD()     Synonym for ORD() in PHPSpreadsheet, which has always used UTF-8 internally
     - TEXTJOIN()   Joins together two or more text strings, separated by a delimiter
   - Logical Functions
     - XOR()        Returns a logical Exclusive Or of all arguments
   - Date/Time Functions
     - ISOWEEKNUM()  Returns the ISO 8601 week number of the year for a given date
   - Lookup and Reference Functions
     - FORMULATEXT()  Returns a formula as a string
   - Engineering Functions
     - ERF.PRECISE()   Returns the error function integrated between 0 and a supplied limit
     - ERFC.PRECISE()  Synonym for ERFC
   - Math and Trig Functions
     - SEC()          Returns the secant of an angle
     - SECH()         Returns the hyperbolic secant of an angle
     - CSC()          Returns the cosecant of an angle
     - CSCH()         Returns the hyperbolic cosecant of an angle
     - COT()          Returns the cotangent of an angle
     - COTH()         Returns the hyperbolic cotangent of an angle
     - ACOT()         Returns the cotangent of an angle
     - ACOTH()        Returns the hyperbolic cotangent of an angle
  - Financial Functions
    - PDURATION()    Calculates the number of periods required for an investment to reach a specified value
    - RRI()          Calculates the interest rate required for an investment to grow to a specified future value
2018-07-22 19:17:04 +01:00
Rolands Usāns eb31899225 Function EXACT(arg1, arg2) support (#595) 2018-07-15 11:56:25 +09:00
Adrien Crivelli 9fdcaabe3c
Could not open CSV file containing HTML fragment
We now always trust the file extension to avoid false positive of mime
detection for most simple cases. But we still try to guess the mime type
if the file extension does not match or is missing.

Fixes #564
2018-06-25 11:12:27 +09:00
Derek Bonner 7a4cbd4fd5 Cell formats with escaped spaces were causing incorrect date formatting
Fix issue where escaped spaces in cell format would cause incorrect
date format leading to incorrect time conversions

Fixes #557
Closes #558
2018-06-24 19:35:45 +09:00
Adrien Crivelli 371c800e3f
Ranges across Z and AA columns incorrectly threw an exception
Fixes #545
2018-06-11 22:54:11 +09:00
Bill Blume e3fb160f5f
Fixed parsing of conditionals in COUNTIF functions
Conditional operators in the selection parameter of COUNTIF
functions were not being parsed properly, causing evaluations
of formulae with such functions to sometimes fail.

Fixes #526
Closes #528
2018-06-10 14:25:33 +09:00
Robin D'Arcy c723833d6f Allow CSV escape character to be set
Fixes #492
Closes #510
2018-05-23 10:31:41 +09:00
Maxim Bulygin 83c759e951
Support to read and write unsupported data for XLSX
This will let users read a file that contains data that are not properly
supported and write them back to a new file untouched.

- load workbookProtection attributes
- save loaded pageSetup[r:id]
- save loaded sheet's AlternateContent
- save loaded unparsed VmlDrawings
- save loaded drawing files `rId`
- save loaded draw's AlternateContent
- save loaded control properties
- save loaded printer settings
- save loaded unparsed override content types (for ctrlProp, ...)

Closes #435
2018-05-12 11:47:46 +09:00
Adrien Crivelli 064076ac6d
Fix unit tests for PHP 5.6 2018-05-07 11:53:55 +09:00
MarkBaker bbe11eed37 Full unit tests for SUBTOTAL function 2018-05-06 23:43:02 +01:00
MarkBaker f08eeaa2ed Code works, but the tests don't yet 2018-04-21 20:34:25 +01:00
MarkBaker 36afa01d33 SUBTOTAL within a SUBTOAL range should be ignored 2018-04-21 01:33:26 +01:00
MarkBaker 04b4e74ec7 Basic unit testing for 100 series actions for SUBTOTAL() with hidden rows/columns 2018-04-20 07:24:11 +01:00
MarkBaker 1ece540254 Basic unit test for SUBTOTAL() function 2018-04-19 22:44:23 +01:00
Josh Grant a089a87671
Avoid losing calculated value type
Closes #394
2018-03-03 11:51:06 +01:00
Josh Grant 148bee1991
Support `_xlfn.` prefix and add `ISFORMULA`, `MODE.SNGL`, `STDEV.S`, `STDEV.P`
This change adds support for newer functions that are prefixed
by _xlfn. (#356). The calculation engine has been updated to
recognise these as functions, and drop the _xlfn. part.

It also add a couple of the new functions such as STDEV.S/P,
MODE.SNGL, ISFORMULA.

Fixes #356
Closes #390
2018-02-26 09:35:53 +01:00
Adrien Crivelli e31878ceb1
Check for MIME type to know if CSV reader can read a file
CSV reader used to accept any file without any kind of check. That made
users incorrectly believe that things were ok, even though there is no
way for CSV reader to read anything else that plain text files.

Fixes #167
2018-02-05 21:33:23 +09:00
MaxTingle 49775bd972
Fix cell ranges causing coordinate merge error
Fixes #319
Closes #328
2018-01-22 12:26:37 +09:00
Adrien Crivelli 481fc4a7c6
Support XML file without styles
Closes #331
Closes https://github.com/PHPOffice/PHPExcel/pull/559
Fixes https://github.com/PHPOffice/PHPExcel/issues/558
2018-01-14 17:08:50 +09:00
Adrien Crivelli bf2dbbaf10
COLUMNS and ROWS functions crashed in some cases
Fixes #336
Fixes https://github.com/PHPOffice/PHPExcel/issues/1383
2018-01-13 18:01:50 +09:00
Adrien Crivelli 36441da330
Fix unit tests for 2018
Closes #311
2018-01-02 00:39:38 +09:00
Adrien Crivelli 139d85d874
Better auto-detection of CSV separators
Closes #305
2017-12-28 12:25:37 +09:00
MarkBaker 90366f9dd1 style fixes 2017-11-26 23:18:11 +00:00
MarkBaker 19fd27811d Improved GCD() evaluation and additional tests 2017-11-26 22:13:29 +00:00
Adrien Crivelli 8d76020590
Consistent `stringFromColumnIndex()` and `columnIndexFromString()`
Column indexes are always based on 1 everywhere in PhpSpreadsheet.
This is consistent with rows starting at 1, as well as Excel
function `COLUMN()`. It should also make it easier to reason about
columns and rows and remove any doubts whether a specific method is
expecting 0 based or 1 based indexes.

Fixes #273
Fixes https://github.com/PHPOffice/PHPExcel/issues/307
Fixes https://github.com/PHPOffice/PHPExcel/issues/476
2017-11-26 15:29:08 +09:00
Maxim 4b4bac53aa INDEX(): fix getting row and col numbers from references (#239)
Allow to use cell references as row and column in function INDEX(). Eg:

```
=INDEX(A1:B5, A9)
```
2017-10-06 14:01:20 +09:00
Maxim 088a76737e Fix DAY() function with 0<x<1 input (#230)
Also bring support for OpenOffice DATE() calculation method
2017-10-04 12:57:01 +09:00
Maxim 810f174d6e Fix INDEX() function when rows count less than row number (#233) 2017-09-30 12:13:20 +09:00
GreatHumorist 2abe56b946 Support missing attribute `r` in `c` node when reading xlsx
When describing a cell, the cell reference (r="A1") is optional.
When not present, we should just increment the index of the last processed row.

Fixes #201 
Closes #225
2017-09-22 14:49:38 +09:00
GreatHumorist 0477e6fcfe In Xml reader throw exception in case of invalid XML (#222)
When the xml file is not a standard xml file, the `simplexml_load_string` will return false, this will cause an error on "$xml->getNamespaces(true);" . So instead of showing the error, we throw an exception.
2017-09-20 14:20:12 +09:00
Bill Blume 2761773b3d
Merge data-validation collections to reduce the final file size
Closes #131
Closes #193
2017-09-08 02:27:18 +09:00
Markus Lanthaler 3ee9cc5ce6
Infer CSV delimiter if it hasn't been set explicitly
Closes #141
2017-04-20 17:02:03 +09:00
Paolo Agostinetto fd83c191ea MATCH function behavior when third parameter is equal to 1 or -1
Fixes #51 
Closes #122
2017-04-01 12:36:02 +09:00
Adrien Crivelli 5fce89e76b Merge pull request #108 from redokun/fix-105
Ods writer: add support for basic text styling (Fix #105)
2017-03-06 11:39:50 +09:00
Christian Schmidt 3560f11935
Replace mbStrReplace() with str_replace()
By design, UTF-8 allows any byte-oriented substring searching algorithm,
since the sequence of bytes for a character cannot occur anywhere else
([source](https://en.wikipedia.org/wiki/UTF-8#Advantages_3)).

So `str_replace()` also works for UTF-8-encoded strings, assuming that
the input strings are valid UTF-8 strings. The previous implementation
of mbStrReplace() did nothing to detect invalid strings.

Also, `str_replace()` does not support [Unicode equivalence](https://en.wikipedia.org/wiki/Unicode_equivalence),
but nor do the other `mb_string` functions, and nor does `=SUBSTITUTE()` in Excel
(tested on Excel for Mac version 15.19.1, Excel 2016 for Windows and LibreOffice 5.1).

Closes #109
2017-03-06 11:33:06 +09:00
Paolo Agostinetto 219e4e6258 Writer\Ods\Content: Set "CompatibilityMode" before and after running the tests in
order to avoid conflicts with other tests
2017-03-04 17:18:18 +01:00
Paolo Agostinetto 4efda2a512 Ods\Writer\Content: added support for xr styles (bold, italic, font family, font size, underline, bg color) 2017-03-04 17:18:18 +01:00
Paolo Agostinetto 5620510991 Writer\Ods\Content: basic unit tests 2017-03-04 17:18:18 +01:00
Paolo Agostinetto c954eddf57 Ods reader: fix sheet count and added a test for sheet names 2017-02-20 21:02:04 +01:00
Paolo Agostinetto 1dba2d1766 Ods reader: tests for repeated spaces and rich text 2017-02-18 20:49:48 +01:00
Paolo Agostinetto bcd1bc364c Ods reader: test loading of Worksheets 2017-02-18 13:55:22 +01:00
Paolo Agostinetto 3c7b2e23da Added unit tests for Ods reader 2017-02-18 13:36:08 +01:00
Adrien Crivelli 8dddf56c2e
Use proper syntax for variadic functions
This simplify code, increase readability and improve the function
signature for API users.
2017-01-23 15:01:20 +09:00
Adrien Crivelli f0445366d2
Fix date related unit tests for 2017 2017-01-04 17:37:23 +09:00
mattkibbler 62345ef4da
Allow start and end date of DATEDIF function to be the same 2016-12-04 19:04:10 +09:00
Matthias Van Woensel 39b8dbd0a1
Adding float cast to MOD function
If $a or $b are not strings, you can get an error that fmod needs param 1 ($a) to be of type double.
MS Excel does not fall over when you insert an empty string in MOD, so I'm guessing PHPExcel should do the same?
2016-12-04 16:12:51 +09:00
Adrien Crivelli e6bbc4bd25
Convert all line ending to unix style 2016-11-27 15:45:15 +09:00
Green Wang 8c58385d6c
Fix cant get right format chinese date format error
modify preg expression in NumberFormat.php

[DBNum1][$-804]yyyy"年"m"月"d"日";@
[DBNum1][$-804]yyyy"年"m"月";@
[DBNum1][$-804]m"月"d"日";@

FIX #44
2016-11-27 13:39:45 +09:00
Alexander Kurilo 408da0c17a Make HTML checks more strict 2016-11-16 22:21:30 +09:00
Alexander Kurilo edb3974a0d Move XEEE test data to add data for other readers 2016-11-16 22:21:30 +09:00
Adrien Crivelli ae1b85f961
Fix code style 2016-10-02 15:21:52 +09:00
Adrien Crivelli 431a1799fb
Fix unit tests for YEARFRAC() 2016-10-02 15:17:52 +09:00
Adrien Crivelli 8c4c11346b
Fix unit tests for DATEDIF()
Leap years where not properly taken into consideration
2016-10-02 14:46:11 +09:00
Adrien Crivelli 60533a4f59
Fix unit tests for WEEKDAY()
In Excel the expected value was incorrect (but it would be different
for LibreOffice)
2016-10-02 09:28:00 +09:00
Adrien Crivelli 23fbc845dd
Fix unit tests for WEEKNUM() 2016-10-01 22:33:12 +09:00
Adrien Crivelli 67918419c4
Fix code style 2016-09-01 12:50:10 +09:00
MarkBaker fb2edfdacf Merge branch 'develop' of https://github.com/PHPOffice/PhpSpreadsheet into develop
# Conflicts:
#	src/Autoloader.php
2016-08-31 21:58:08 +01:00
MarkBaker fae27a6d63 As iconv is now enabled by default in PHP, make it a requirement, and modify strig functions to use it where appropriate 2016-08-31 21:52:42 +01:00
Adrien Crivelli a85f1bdbed
Apply Scrutinizer patches for spacing 2016-08-25 18:46:02 +09:00
Adrien Crivelli 20ccfa0d59
Fix unit tests for MDETERM() 2016-08-25 14:23:26 +09:00
Adrien Crivelli 09d456e477
Introduce PHP-CS-Fixer for stricter code style rules
PHP-CS-Fixer allow to check different things than phpcs and it allows
code to be more consistent. Configuration can be changed in `.php_cs`
2016-08-17 00:33:57 +09:00
Adrien Crivelli 539a89a918
Rename namespace `PHPExcel` to `PhpSpreadsheet`
This also fix a few bugs that were introduced when migrating to
namespace. Some non-namespaces classes were leftover

FIX #15
2016-08-16 23:24:47 +09:00
Adrien Crivelli e1f81f0fe0
Refactor tests data from custom format to PHP
FIX #14
2016-08-16 21:00:19 +09:00