From 19cc7f8b27f6fead990509e9aa8dcbe59940631a Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 5 Mar 2021 10:37:19 +0300 Subject: [PATCH] update add row data update for difficult structure [[0=>"first",2=>"third"],[1=>"second",3=>"forth"]] --- xlsxwriter.class.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php index 0e8033e27..b2f945ea7 100644 --- a/xlsxwriter.class.php +++ b/xlsxwriter.class.php @@ -275,13 +275,15 @@ public function writeSheetRow($sheet_name, array $row, $row_options=null) } $style = &$row_options; - $c=0; - foreach ($row as $v) { - $number_format = $sheet->columns[$c]['number_format']; - $number_format_type = $sheet->columns[$c]['number_format_type']; - $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++; + $rowKeys = array_key($row); + $maxCellIndex = end($rowKeys); + for($cellIndex = 0; $cellIndex <= $maxCellIndex; $cellIndex++){ + $value = $row[$cellIndex] ?? ''; + + $number_format = $sheet->columns[$cellIndex]['number_format']; + $number_format_type = $sheet->columns[$cellIndex]['number_format_type']; + $cell_style_idx = empty($style) ? $sheet->columns[$cellIndex]['default_cell_style'] : $this->addCellStyle( $number_format, json_encode(isset($style[0]) ? $style[$cellIndex] : $style) ); + $this->writeCell($sheet->file_writer, $sheet->row_count, $cellIndex, $value, $number_format_type, $cell_style_idx); } $sheet->file_writer->write(''); $sheet->row_count++;