From bc3091578ed845560b384a120251a01e2470b622 Mon Sep 17 00:00:00 2001 From: Athena Metis Date: Sat, 25 Aug 2018 10:25:38 +0100 Subject: [PATCH 1/4] Allow for the auto_filter option value >1 to offset the start row of the auto filter range. Backwards Compatibility: Setting this option to true (old style) is already converted to 1 so backwards compability is still preserved, an additional is_int check is added for extra caution. Use case: multi row headings where the auto filter dropdown row may be desired as the second row rather than the first Usage: Setting the auto_filter option to 2 would result in the auto filter dropdowns and the data being filtered starting on row 2, this can be any number from 1-X and will offset the auto filter range respectively. --- xlsxwriter.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php index a987735f8..8400118f5 100644 --- a/xlsxwriter.class.php +++ b/xlsxwriter.class.php @@ -308,7 +308,7 @@ protected function finalizeSheet($sheet_name) $max_cell = self::xlsCell($sheet->row_count - 1, count($sheet->columns) - 1); if ($sheet->auto_filter) { - $sheet->file_writer->write( ''); + $sheet->file_writer->write( ''); } $sheet->file_writer->write( ''); @@ -666,7 +666,7 @@ protected function buildWorkbookXML() foreach($this->sheets as $sheet_name=>$sheet) { if ($sheet->auto_filter) { $sheetname = self::sanitize_sheetname($sheet->sheetname); - $workbook_xml.=''; + $workbook_xml.=''; $i++; } } From f25c54c5b5ad9af3a1f135d0dd191d51b609ee6e Mon Sep 17 00:00:00 2001 From: Athena Metis Date: Sat, 25 Aug 2018 10:34:26 +0100 Subject: [PATCH 2/4] Updated auto_filter example to include documentation on the offsetting the auto filter start row --- examples/ex09-autofilter.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/ex09-autofilter.php b/examples/ex09-autofilter.php index c415e05a9..2c7d12b0b 100644 --- a/examples/ex09-autofilter.php +++ b/examples/ex09-autofilter.php @@ -5,7 +5,19 @@ $chars = 'abcdefgh'; $writer = new XLSXWriter(); -$writer->writeSheetHeader('Sheet1', array('col-string'=>'string','col-numbers'=>'integer','col-timestamps'=>'datetime'), ['auto_filter'=>true, 'widths'=>[15,15,30]] ); + +/** + * auto_filter may also be set to numbers greater than 1 to offset the + * start row for the auto filter data range. This will have the effect + * of changing the start row for the data to be filtered and there-by + * the row the dropdown filters show on to the row number specified + * in this option. + */ +$writer->writeSheetHeader( + 'Sheet1', + ['col-string'=>'string', 'col-numbers'=>'integer', 'col-timestamps'=>'datetime'], + ['auto_filter'=>1, 'widths'=>[15, 15, 30]] +); for($i=0; $i<1000; $i++) { $writer->writeSheetRow('Sheet1', array( From 22b4df21ac0474e5d83a5ea8ecd0db4ca583e1fd Mon Sep 17 00:00:00 2001 From: Athena Metis Date: Mon, 27 Aug 2018 09:32:05 +0100 Subject: [PATCH 3/4] Updated composer.json to be a separate packagist package --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9e0987082..0e12b9f0c 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "mk-j/php_xlsxwriter", - "description": "PHP Library to write XLSX files", + "name": "athena-metis/php_xlsxwriter", + "description": "PHP Library to write XLSX files (Fork of mk-j/php_xlsxwriter)", "keywords": ["php", "library","xls", "xlsx", "excel"], "type": "project", - "homepage": "https://github.com/mk-j/PHP_XLSXWriter", + "homepage": "https://github.com/athena-metis/PHP_XLSXWriter", "license": "MIT", "autoload": { From 2a9dc3235804afda16cb60497ed3388c4a6083f4 Mon Sep 17 00:00:00 2001 From: Athena Metis Date: Wed, 3 Oct 2018 10:46:15 +0100 Subject: [PATCH 4/4] Allow for the number format to be overridden for a writeSheetRow operation (this is currently coarse in that it only allows for one override type for the whole row, not per column) This is intended to allow for interim headers to be added similar to how headers are added --- xlsxwriter.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php index 8400118f5..85ec981fd 100644 --- a/xlsxwriter.class.php +++ b/xlsxwriter.class.php @@ -254,9 +254,13 @@ public function writeSheetRow($sheet_name, array $row, $row_options=null) $default_column_types = $this->initializeColumnTypes( array_fill($from=0, $until=count($row), 'GENERAL') );//will map to n_auto $sheet->columns = array_merge((array)$sheet->columns, $default_column_types); } - + + $overrideNumberFormats = null; if (!empty($row_options)) { + $overrideNumberFormats = isset($row_options['number_format']) ? $row_options['number_format'] : null; + if (!empty($row_options['number_format'])) { unset($row_options['number_format']); } + $ht = isset($row_options['height']) ? floatval($row_options['height']) : 12.1; $customHt = isset($row_options['height']) ? true : false; $hidden = isset($row_options['hidden']) ? (bool)($row_options['hidden']) : false; @@ -274,7 +278,7 @@ public function writeSheetRow($sheet_name, array $row, $row_options=null) $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); + $this->writeCell($sheet->file_writer, $sheet->row_count, $c, $v, !empty($overrideNumberFormats) ? $overrideNumberFormats : $number_format_type, $cell_style_idx); $c++; } $sheet->file_writer->write('');