Files
PhpSpreadsheet/docs/topics/settings.md
T
oleibman 365f9f1995 Compact Function List by Name Document
The entries in the "function list by name" document are very long, and almost all of them require horizontal scrolling, which is not very convenient for the end-user. This PR creates a "function list by name compact" document, in which `CATEGORY_` is stripped from all the category names and `PhpOffice\PhpSpreadsheet\Calculation\` is stripped from all the functions. I believe this eliminates the need to scroll horizontally within the document. I waffled on whether this should replace the existing document, or whether it should be an additional document. I decided there was probably some merit in keeping the old, and hardly any down-side, so, at least for now, we will generate both documents, and they will link to each other.

No changes to source code.
2025-05-23 08:32:52 -07:00

1.9 KiB

Configuration Settings

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.

Cell collection caching

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.

To enable cell caching, you must provide your own implementation of cache like so:

$cache = new MyCustomPsr16Implementation();

\PhpOffice\PhpSpreadsheet\Settings::setCache($cache);

Language/Locale

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:

$locale = 'pt_br';
$validLocale = \PhpOffice\PhpSpreadsheet\Settings::setLocale($locale);
if (!$validLocale) {
    echo 'Unable to set locale to ' . $locale . " - reverting to en_us" . PHP_EOL;
}
  • If Brazilian Portuguese language files aren't available, then Portuguese will be enabled instead
  • If Portuguese language files aren't available, then the setLocale() method will return an error, and American English (en_us) settings will be used throughout.

More details of the features available once a locale has been set, including a list of the languages and locales currently supported, can be found in Locale Settings for Formulas.

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:

use GuzzleHttp\Client;
use Http\Factory\Guzzle\RequestFactory;
use PhpOffice\PhpSpreadsheet\Settings;

$client = new Client();
$requestFactory = new RequestFactory();

Settings::setHttpClient($client, $requestFactory);