// Look up the value by the column keys to ensure the correct order of values
foreach (array_keys($column_headings) as $column_index => $column_key) {
- $sheet->setCellValueByColumnAndRow($column_index, $current_row, $cart_item[$column_key]);
$current_cell_style = $sheet->getStyleByColumnAndRow($column_index, $current_row);
- if (in_array($column_key, ['PRIX HT', 'PRIX TTC'])) {
- $current_cell_style->getNumberFormat()->setFormatCode($euro_currency_format);
- } elseif (in_array($column_key, ['QTE', 'QTE MINI'])) {
- $current_cell_style->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
+ switch($column_key) {
+ case 'EAN': // Ensure EAN doesn't contain commas (it's a number, not a string)
+ $EAN = str_replace(',', '', $cart_item[$column_key]);
+ $sheet->setCellValueByColumnAndRow($column_index, $current_row, $EAN);
+ $current_cell_style->getNumberFormat()->setFormatCode('#,##0'); // Comma separated, no decimals
+ break;
+ case 'REF': // Explicitly store REF as text in order to preserve leading zeros
+ $sheet->setCellValueExplicitByColumnAndRow($column_index, $current_row, $cart_item[$column_key], PHPExcel_Cell_DataType::TYPE_STRING);
+ break;
+ case 'PRIX HT':
+ case 'PRIX TTC':
+ $sheet->setCellValueByColumnAndRow($column_index, $current_row, $cart_item[$column_key]);
+ $current_cell_style->getNumberFormat()->setFormatCode($euro_currency_format);
+ break;
+ case 'QTE':
+ case 'QTE MINI':
+ $sheet->setCellValueByColumnAndRow($column_index, $current_row, $cart_item[$column_key]);
+ $current_cell_style->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
+ break;
+ default:
+ $sheet->setCellValueByColumnAndRow($column_index, $current_row, $cart_item[$column_key]);
}
}