Just use .Xlsx and run away from .CSV(it’s easily breakable).Leave a Comment
PHP Excel Master Posts
Setting a formula to a Cell
- Write a formula into a cell
- Locale Settings for Formulae
- Formula pre-calculation
- Performing formula calculations
- Formulas involving numbers and text
- Disable Cache
- Flush Cache
Setting a formula in a Cell
PhpSpreadsheet parses everything that starts with = as a formula, and to get the value of a cell that contains a formula you use the function getCalculatedValue()
If you want to use ‘=’ as part of a string and not to be parsed as a formula, you will need to escape
To do this, you need to “escape” the value by setting it as “quoted text”.\
Locale Settings for Formulae
You can also create a formula using the function names and argument separators appropriate to the defined locale; then translate it to English before setting the cell value:
Currently, formula translation only translates the function names, the constants TRUE and FALSE, and the function argument separators.
Performing formula calculations
Formulas involving numbers and text
Formulas involving numbers and text may produce unexpected results or even unreadable file contents. For example, the formula =3+”Hello ” is expected to produce an error in Excel (#VALUE!). Due to the fact that PHP converts “Hello ” to a numeric value (zero), the result of this formula is evaluated as 3 instead of evaluating as an error. This also causes the Excel document being generated as containing unreadable content.
Will disable calculation caching, and flush the current calculation cache.
If you want only to flush the cache, then you can callLeave a Comment
Reading data from a spreadsheet can be done in multiple ways:
- Read a file using automatic file type detection
- Read a file by specifying the file type
- Read a file and opening specific worksheets
- Read a file in read-only mode
- Read a file and open only specific cells
How to read a file, by automatically detecting the file type
You should use this when you don’t know what file format the user will load.
How to read a file by specifying the file type:
This is faster than using the automatically detecting file type.
How to load only specific worksheets
How to open a file in read-only mode
How to read specific cells:
The following code will only read row 1 and rows 20 – 30 of any sheet in the Excel file:Leave a Comment
The simplest way of installing PHPSpreadSheet is to use Composer.
Here are the requirements for running this library:
- PHP 5.6 (min version)
- PHP extension php_xml enabled
- PHP extension php_gd2 enabled (if not compiled in)
- PHP extension php_zip enabled
The PHP extensions should be already enabled, with a standard PHP installation(I didn’t have to enable any extension when I was installing it for the first time).
To install the library we will use Composer:
If you don’t have composer installed on your current machine, here is a how to install it.
After the process was finished, you can test if it’s working correctly using this simple code:
This should generate a new spreadsheet that looks like this:Leave a Comment