(Many thanks to the author for providing us with this very useful library!)
There are times when I need to override the format of a certain column, based on that column's value in the current row.
For example, I define 'postcode' as 'integer' at the column level.
However, some rows can have non-numeric postcodes. In such cases, I want to be able to override the format_type and set it to 'integer'.
This can be achieved with the following mods to writeSheetRow()
/* was foreach ($row as $v) { */
/* is */ foreach ($row as $k => $v) {
$number_format = $sheet->columns[$c]['number_format'];
$number_format_type = $sheet->columns[$c]['number_format_type'];
// rest of changes start here
if (key_exists($k, $row_options)) {
if (key_exists('number_format', $row_options[$k])) {
$number_format = $row_options[$k]['number_format'];
}
if (key_exists('number_format_type', $row_options[$k])) {
$number_format_type = $row_options[$k]['number_format_type'];
}
}**
// changes end here
$cell_style_idx = empty($style) ? $sheet->columns[$c]['default_cell_style'] : $this->addCellStyle($number_format, json_encode(isset($style[0]) ? $style[$c] : $style));
$this->writeCell($sheet->file_writer, $sheet->row_count, $c, $v, $number_format_type, $cell_style_idx);
$c++;
}
The caller simply needs to provide the extra formatting info, as follows
('// changes start here' marks the relevant code. The rest is for context)
(Many thanks to the author for providing us with this very useful library!)
There are times when I need to override the format of a certain column, based on that column's value in the current row. For example, I define 'postcode' as 'integer' at the column level. However, some rows can have non-numeric postcodes. In such cases, I want to be able to override the format_type and set it to 'integer'.
This can be achieved with the following mods to writeSheetRow()
The caller simply needs to provide the extra formatting info, as follows ('// changes start here' marks the relevant code. The rest is for context)