2016-12-03 13:16:45 +00:00
|
|
|
# Configuration Settings
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
Once you have included the PhpSpreadsheet files in your script, but
|
|
|
|
before instantiating a `Spreadsheet` object or loading a workbook file,
|
|
|
|
there are a number of configuration options that can be set which will
|
|
|
|
affect the subsequent behaviour of the script.
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2017-04-14 05:22:33 +00:00
|
|
|
## Cell collection caching
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2017-04-14 05:22:33 +00:00
|
|
|
By default, PhpSpreadsheet holds all cell objects in memory, but
|
|
|
|
you can specify alternatives to reduce memory consumption at the cost of speed.
|
|
|
|
Read more about [memory saving](./memory_saving.md).
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2017-04-14 05:22:33 +00:00
|
|
|
To enable cell caching, you must provide your own implementation of cache like so:
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2020-05-31 13:41:05 +00:00
|
|
|
```php
|
2017-04-14 05:22:33 +00:00
|
|
|
$cache = new MyCustomPsr16Implementation();
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2017-04-14 05:22:33 +00:00
|
|
|
\PhpOffice\PhpSpreadsheet\Settings::setCache($cache);
|
2013-05-16 20:59:54 +00:00
|
|
|
```
|
|
|
|
|
2016-12-03 13:16:45 +00:00
|
|
|
## Language/Locale
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
Some localisation elements have been included in PhpSpreadsheet. You can
|
|
|
|
set a locale by changing the settings. To set the locale to Brazilian
|
|
|
|
Portuguese you would use:
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2020-05-31 13:41:05 +00:00
|
|
|
```php
|
2013-05-16 20:59:54 +00:00
|
|
|
$locale = 'pt_br';
|
2016-11-27 15:51:44 +00:00
|
|
|
$validLocale = \PhpOffice\PhpSpreadsheet\Settings::setLocale($locale);
|
2013-05-16 20:59:54 +00:00
|
|
|
if (!$validLocale) {
|
2013-05-19 21:14:52 +00:00
|
|
|
echo 'Unable to set locale to ' . $locale . " - reverting to en_us" . PHP_EOL;
|
2013-05-16 20:59:54 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-03-12 02:02:43 +00:00
|
|
|
- If Brazilian Portuguese language files aren't available, then Portuguese
|
|
|
|
will be enabled instead
|
|
|
|
- If Portuguese language files aren't available,
|
2017-03-13 05:57:37 +00:00
|
|
|
then the `setLocale()` method will return an error, and American English
|
2016-12-03 15:00:54 +00:00
|
|
|
(en\_us) settings will be used throughout.
|
2013-05-16 20:59:54 +00:00
|
|
|
|
2016-12-03 15:00:54 +00:00
|
|
|
More details of the features available once a locale has been set,
|
|
|
|
including a list of the languages and locales currently supported, can
|
2017-03-12 02:02:43 +00:00
|
|
|
be found in [Locale Settings for
|
|
|
|
Formulae](./recipes.md#locale-settings-for-formulae).
|
2020-07-19 02:33:01 +00:00
|
|
|
|
|
|
|
## HTTP client
|
|
|
|
|
|
|
|
In order to use the `WEBSERVICE` function in formulae, you must configure an
|
|
|
|
HTTP client. Assuming you chose Guzzle 7, this can be done like:
|
|
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use Http\Factory\Guzzle\RequestFactory;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Settings;
|
|
|
|
|
|
|
|
$client = new Client();
|
|
|
|
$requestFactory = new RequestFactory();
|
|
|
|
|
|
|
|
Settings::setHttpClient($client, $requestFactory);
|
|
|
|
```
|