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": { 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( diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php index a987735f8..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(''); @@ -308,7 +312,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 +670,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++; } }