mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
1.2.16
This commit is contained in:
parent
82b0db1f8e
commit
aff0fa243d
@ -1,9 +1,10 @@
|
||||
# Changelog
|
||||
## 1.2.16 (2022-08-06)
|
||||
* added modTemplate( $path, $custom_xml ) for customize generated XML
|
||||
## 1.2.16 (2022-08-12)
|
||||
* added `autoFilter( $range )`
|
||||
```php
|
||||
$xlsx->modTemplate('xl/worksheets/sheet1.xml', '<autoFilter ref="A1:A5"/>');
|
||||
$xlsx->autoFilter('A2:B10');
|
||||
```
|
||||
* fixed `0%` bug
|
||||
|
||||
## 1.2.15 (2022-07-05)
|
||||
* added wrap words in long strings `<wraptext>long long line</wraptext>`
|
||||
|
@ -105,8 +105,8 @@ $xlsx->addSheet( $books2, 'Stephen King catalog');
|
||||
$xlsx->downloadAs('books_2021.xlsx');
|
||||
exit();
|
||||
|
||||
// Customize XML
|
||||
$xlsx->modTemplate('xl/worksheets/sheet1.xml', '<autoFilter ref="A1:A5"/>');
|
||||
// Autofilter
|
||||
$xlsx->autoFilter('A1:B10');
|
||||
|
||||
```
|
||||
### JS array to Excel (AJAX)
|
||||
|
@ -55,7 +55,7 @@ class SimpleXLSXGen {
|
||||
public function __construct() {
|
||||
$this->curSheet = -1;
|
||||
$this->defaultFont = 'Calibri';
|
||||
$this->sheets = [ ['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [] ] ];
|
||||
$this->sheets = [ ['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '' ] ];
|
||||
$this->SI = []; // sharedStrings index
|
||||
$this->SI_KEYS = []; // & keys
|
||||
$this->XF = [ // styles
|
||||
@ -90,7 +90,7 @@ class SimpleXLSXGen {
|
||||
'xl/worksheets/sheet1.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
||||
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
||||
><dimension ref="{REF}"/>{COLS}<sheetData>{ROWS}</sheetData>{MERGECELLS}{HYPERLINKS}</worksheet>',
|
||||
><dimension ref="{REF}"/>{COLS}<sheetData>{ROWS}</sheetData>{AUTOFILTER}{MERGECELLS}{HYPERLINKS}</worksheet>',
|
||||
'xl/worksheets/_rels/sheet1.xml.rels' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">{HYPERLINKS}</Relationships>',
|
||||
'xl/sharedStrings.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
@ -157,7 +157,7 @@ class SimpleXLSXGen {
|
||||
}
|
||||
}
|
||||
|
||||
$this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => []];
|
||||
$this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '' ];
|
||||
|
||||
if ( isset( $rows[0] ) && is_array($rows[0]) ) {
|
||||
$this->sheets[$this->curSheet]['rows'] = $rows;
|
||||
@ -620,7 +620,7 @@ class SimpleXLSXGen {
|
||||
$N = 0;
|
||||
}
|
||||
}
|
||||
if ( !$cv) {
|
||||
if ( $cv === null ) {
|
||||
|
||||
$v = $this->esc( $v );
|
||||
|
||||
@ -697,6 +697,11 @@ class SimpleXLSXGen {
|
||||
$REF = 'A1:A1';
|
||||
}
|
||||
|
||||
$AUTOFILTER = '';
|
||||
if ($this->sheets[$idx]['autofilter']) {
|
||||
$AUTOFILTER = '<autoFilter ref="'.$this->sheets[$idx]['autofilter'].'" />';
|
||||
}
|
||||
|
||||
$MERGECELLS = [];
|
||||
if ( count($this->sheets[$idx]['mergecells']) ) {
|
||||
$MERGECELLS[] = '';
|
||||
@ -715,11 +720,18 @@ class SimpleXLSXGen {
|
||||
}
|
||||
$HYPERLINKS[] = '</hyperlinks>';
|
||||
}
|
||||
|
||||
//restore locale
|
||||
setlocale(LC_NUMERIC, $_loc);
|
||||
|
||||
return str_replace(['{REF}','{COLS}','{ROWS}','{MERGECELLS}','{HYPERLINKS}'],
|
||||
[ $REF, implode("\r\n", $COLS), implode("\r\n",$ROWS), implode("\r\n", $MERGECELLS), implode("\r\n", $HYPERLINKS) ],
|
||||
return str_replace(['{REF}','{COLS}','{ROWS}','{AUTOFILTER}','{MERGECELLS}','{HYPERLINKS}'],
|
||||
[ $REF,
|
||||
implode("\r\n", $COLS),
|
||||
implode("\r\n",$ROWS),
|
||||
$AUTOFILTER,
|
||||
implode("\r\n", $MERGECELLS),
|
||||
implode("\r\n", $HYPERLINKS)
|
||||
],
|
||||
$template );
|
||||
}
|
||||
|
||||
@ -768,11 +780,12 @@ class SimpleXLSXGen {
|
||||
$this->defaultFontSize = $size;
|
||||
return $this;
|
||||
}
|
||||
public function modTemplate( $path, $custom_xml ) {
|
||||
$t = $this->template[ $path ];
|
||||
$p = strrpos($t,'</');
|
||||
return $this->template[ $path ] = substr($t, 0, $p) . $custom_xml . substr($t,$p);
|
||||
|
||||
public function autoFilter( $range ) {
|
||||
$this->sheets[$this->curSheet]['autofilter'] = $range;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function mergeCells( $range ) {
|
||||
$this->sheets[$this->curSheet]['mergecells'][] = $range;
|
||||
return $this;
|
||||
|
Loading…
Reference in New Issue
Block a user