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