Repository navigation
dev/core#6927 issue with download to excel from search kit - #38019
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
|
The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/6927 |
4038fa6 to
4d53629
Compare
|
Thanks for this, @jaapjansma A couple things:
Instead of modifying the type after setting the value, what do you think about setting it explicitly upfront if the formatted value begins with $formattedValue = $this->formatColumnValue($col, $value);
if (is_string($formattedValue) && str_starts_with($formattedValue, '=')) {
$cell->setValueExplicit($formattedValue, DataType::TYPE_STRING);
}
else {
$cell->setValue($formattedValue);
}This:
|
|
@colemanw happy to implement your suggestion. But rather for checking whether the value is a string. We can also check if the value has a data type Int or Float to set it to numeric. And default data type to string. What do you think? $formattedValue = $this->formatColumnValue($col, $value);
$dataType = DataType::TYPE_STRING;
if ($value['dataType'] === 'Int' || $value['dataType'] == 'Float') {
$dataType = DataType::TYPE_NUMERIC;
}
$cell->setValueExplicit($formattedValue, $dataType); |
|
@jaapjansma I think that would break Date, Timestamp, Money, and Boolean data types. Also core doesn't always use 'Int', Api4 uses 'Integer'. I think the simplest fix is to let PhpSpreadsheet handle normal types, and only override when using a string with '=': $formattedValue = $this->formatColumnValue($col, $value);
if (is_string($formattedValue) && str_starts_with($formattedValue, '=')) {
$cell->setValueExplicit($formattedValue, DataType::TYPE_STRING);
}
else {
$cell->setValue($formattedValue);
} |
|
Makes sense. |
c63f6f4 to
28ad256
Compare
28ad256 to
12cc0b0
Compare
Overview
When exporting data to excel from a search kit and one of the columns starts with
=then the export fails.In our client database they have phone numbers stored as
= secretary 061234And I know this is not ideal but it is possible. And this bug will probably also happen when another field starts=.This causes the export think it is an excel formula. This PR sets the column data type to
Stringwhen the data type of the data is also aString.This PR also changes the unit test to specifically test for a column starting with a
=.Reproduction steps
Current behaviour
Export hangs.
The log file reads
Argument #1 ($array) must be of type array, string given" in /home/pdcdeherberg/www/testcrm/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php on line 2049Expected behaviour
The excel file can be downloaded
Environment information
Comments
The log file contains: