Hi RolandD
I modified
administrator\components\com_csvi\assets\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Worksheet\Worksheet.php
Following works for me by modifying the fromArray function.
/**
* Price column.
*
* @var string
*/
private $priceColumn = '';
public function fromArray(array $source, $nullValue = null, $startCell = 'A1', $strictNullComparison = false)
{
// Convert a 1-D array to 2-D (for ease of looping)
if (!is_array(end($source))) {
$source = [$source];
}
// start coordinate
[$startColumn, $startRow] = Coordinate::coordinateFromString($startCell);
$foundPrice = false;
// Loop through $source
foreach ($source as $rowData) {
$currentColumn = $startColumn;
foreach ($rowData as $cellValue) {
// get column header
// if ($field->number_field)
$is_price = false;
if ($startRow > 1 && $this->priceColumn == '' && $this->priceColumn !== '99' ) {
$column_header = $this->getCell($currentColumn . 1)->getValue();
if(stripos($column_header, 'price') !== false){
$is_price = true;
$foundPrice = true;
$this->priceColumn = $currentColumn;
}
}
elseif ($startRow > 1 && $currentColumn == $this->priceColumn) {
$is_price = true; $foundPrice = true;
}
if ($strictNullComparison) {
if ($cellValue !== $nullValue) {
// Set cell value
if ($is_price) {
$this->getCell($currentColumn . $startRow)->setValueExplicit($cellValue, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$this->getStyle($currentColumn . $startRow)->getNumberFormat()->setFormatCode('#,##0.00');
} else {
// original
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
}
}
} else {
if ($cellValue != $nullValue) {
// Set cell value
if ($is_price) {
$this->getCell($currentColumn . $startRow)->setValueExplicit($cellValue, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
$this->getStyle($currentColumn . $startRow)->getNumberFormat()->setFormatCode('#,##0.00');
} else {
// original
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
}
}
}
++$currentColumn;
}
if ($startRow > 1 && !$foundPrice) $this->priceColumn = '99';
++$startRow;
}
return $this;
}
regards
Eliot