mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
1.1.12
This commit is contained in:
parent
1c206d06bc
commit
c3d10db967
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
# 1.1.12 (2022-03-15)
|
||||||
|
* Added $xlsx->mergeCells('A1:C1')
|
||||||
|
|
||||||
## 1.1.11 (2022-02-05)
|
## 1.1.11 (2022-02-05)
|
||||||
* sheet name maximum length is 31 chars, mb_substr used now
|
* sheet name maximum length is 31 chars, mb_substr used now
|
||||||
* license fixed
|
* license fixed
|
||||||
|
@ -66,11 +66,13 @@ $data = [
|
|||||||
['Left', '<left>12345.67</left>'],
|
['Left', '<left>12345.67</left>'],
|
||||||
['Center', '<center>12345.67</center>'],
|
['Center', '<center>12345.67</center>'],
|
||||||
['Right', '<right>Right Text</right>'],
|
['Right', '<right>Right Text</right>'],
|
||||||
['Center + Bold', '<center><b>Name</b></center>']
|
['Center + Bold', '<center><b>Name</b></center>'],
|
||||||
|
['<center>MERGE CELLS</center>']
|
||||||
];
|
];
|
||||||
Shuchkin\SimpleXLSXGen::fromArray( $data )
|
Shuchkin\SimpleXLSXGen::fromArray( $data )
|
||||||
->setDefaultFont( 'Courier New' )
|
->setDefaultFont( 'Courier New' )
|
||||||
->setDefaultFontSize( 14 )
|
->setDefaultFontSize( 14 )
|
||||||
|
->mergeCells('A13:B13')
|
||||||
->saveAs('styles_and_tags.xlsx');
|
->saveAs('styles_and_tags.xlsx');
|
||||||
```
|
```
|
||||||
![XLSX screenshot](styles.png)
|
![XLSX screenshot](styles.png)
|
||||||
|
@ -39,7 +39,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' => [] ] ];
|
$this->sheets = [ ['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [] ] ];
|
||||||
$this->SI = []; // sharedStrings index
|
$this->SI = []; // sharedStrings index
|
||||||
$this->SI_KEYS = []; // & keys
|
$this->SI_KEYS = []; // & keys
|
||||||
$this->F = [ self::F_NORMAL ]; // fonts
|
$this->F = [ self::F_NORMAL ]; // fonts
|
||||||
@ -72,7 +72,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>{HYPERLINKS}</worksheet>',
|
><dimension ref="{REF}"/>{COLS}<sheetData>{ROWS}</sheetData>{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"?>
|
||||||
@ -139,7 +139,7 @@ class SimpleXLSXGen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => []];
|
$this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => [], 'mergecells' => []];
|
||||||
|
|
||||||
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;
|
||||||
@ -440,12 +440,13 @@ class SimpleXLSXGen {
|
|||||||
if ( !isset($COL[ $CUR_COL ])) {
|
if ( !isset($COL[ $CUR_COL ])) {
|
||||||
$COL[ $CUR_COL ] = 0;
|
$COL[ $CUR_COL ] = 0;
|
||||||
}
|
}
|
||||||
|
$cname = $this->num2name($CUR_COL) . $CUR_ROW;
|
||||||
|
|
||||||
if ( $v === null || $v === '' ) {
|
if ( $v === null || $v === '' ) {
|
||||||
|
$row .= '<c r="'.$cname.'"/>';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cname = $this->num2name($CUR_COL) . $CUR_ROW;
|
|
||||||
|
|
||||||
$ct = $cv = null;
|
$ct = $cv = null;
|
||||||
$N = $F = $A = 0;
|
$N = $F = $A = 0;
|
||||||
|
|
||||||
@ -564,7 +565,7 @@ class SimpleXLSXGen {
|
|||||||
$cv = $v;
|
$cv = $v;
|
||||||
} elseif ( $v instanceof \DateTime ) {
|
} elseif ( $v instanceof \DateTime ) {
|
||||||
$vl = 16;
|
$vl = 16;
|
||||||
$cv = $this->date2excel( $v->format('Y'), $v->format('m'), $v->format('d'), $v->format('H'), $v->format('i'), $v->format('s') );
|
$cv = $this->date2excel($v->format('Y'), $v->format('m'), $v->format('d'), $v->format('H'), $v->format('i'), $v->format('s'));
|
||||||
$N = self::N_DATETIME; // [22] m/d/yy h:mm
|
$N = self::N_DATETIME; // [22] m/d/yy h:mm
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@ -593,8 +594,8 @@ class SimpleXLSXGen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$row .= '<c r="' . $cname . '"'.($ct ? ' t="'.$ct.'"' : '').($cs ? ' s="'.$cs.'"' : '').'>'
|
$row .= '<c r="' . $cname . '"' . ($ct ? ' t="' . $ct . '"' : '') . ($cs ? ' s="' . $cs . '"' : '') . '>'
|
||||||
.($ct === 'inlineStr' ? '<is><t>'.$cv.'</t></is>' : '<v>' . $cv . '</v>')."</c>\r\n";
|
. ($ct === 'inlineStr' ? '<is><t>' . $cv . '</t></is>' : '<v>' . $cv . '</v>') . "</c>\r\n";
|
||||||
}
|
}
|
||||||
$ROWS[] = $row . "</row>\r\n";
|
$ROWS[] = $row . "</row>\r\n";
|
||||||
}
|
}
|
||||||
@ -602,11 +603,22 @@ class SimpleXLSXGen {
|
|||||||
$COLS[] = '<col min="'.$k.'" max="'.$k.'" width="'.min( $max+1, 60).'" />';
|
$COLS[] = '<col min="'.$k.'" max="'.$k.'" width="'.min( $max+1, 60).'" />';
|
||||||
}
|
}
|
||||||
$COLS[] = '</cols>';
|
$COLS[] = '</cols>';
|
||||||
$REF = 'A1:'.$this->num2name(count($COLS)) . $CUR_ROW;
|
$REF = 'A1:'.$this->num2name(count($COL)) . $CUR_ROW;
|
||||||
} else {
|
} else {
|
||||||
$ROWS[] = '<row r="1"><c r="A1" t="s"><v>0</v></c></row>';
|
$ROWS[] = '<row r="1"><c r="A1" t="s"><v>0</v></c></row>';
|
||||||
$REF = 'A1:A1';
|
$REF = 'A1:A1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$MERGECELLS = [];
|
||||||
|
if ( count($this->sheets[$idx]['mergecells']) ) {
|
||||||
|
$MERGECELLS[] = '';
|
||||||
|
$MERGECELLS[] = '<mergeCells count="'.count($this->sheets[$idx]['mergecells']).'">';
|
||||||
|
foreach( $this->sheets[$idx]['mergecells'] as $m ) {
|
||||||
|
$MERGECELLS[] = '<mergeCell ref="'.$m.'"/>';
|
||||||
|
}
|
||||||
|
$MERGECELLS[] = '</mergeCells>';
|
||||||
|
}
|
||||||
|
|
||||||
$HYPERLINKS = [];
|
$HYPERLINKS = [];
|
||||||
if ( count( $this->sheets[$idx]['hyperlinks']) ) {
|
if ( count( $this->sheets[$idx]['hyperlinks']) ) {
|
||||||
$HYPERLINKS[] = '<hyperlinks>';
|
$HYPERLINKS[] = '<hyperlinks>';
|
||||||
@ -618,8 +630,8 @@ class SimpleXLSXGen {
|
|||||||
//restore locale
|
//restore locale
|
||||||
setlocale(LC_NUMERIC, $_loc);
|
setlocale(LC_NUMERIC, $_loc);
|
||||||
|
|
||||||
return str_replace(['{REF}','{COLS}','{ROWS}','{HYPERLINKS}'],
|
return str_replace(['{REF}','{COLS}','{ROWS}','{MERGECELLS}','{HYPERLINKS}'],
|
||||||
[ $REF, implode("\r\n", $COLS), implode("\r\n",$ROWS), implode("\r\n", $HYPERLINKS) ],
|
[ $REF, implode("\r\n", $COLS), implode("\r\n",$ROWS), implode("\r\n", $MERGECELLS), implode("\r\n", $HYPERLINKS) ],
|
||||||
$template );
|
$template );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,6 +680,10 @@ class SimpleXLSXGen {
|
|||||||
$this->defaultFontSize = $size;
|
$this->defaultFontSize = $size;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
public function mergeCells( $range ) {
|
||||||
|
$this->sheets[$this->curSheet]['mergecells'][] = $range;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
public function esc( $str ) {
|
public function esc( $str ) {
|
||||||
// XML UTF-8: #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
// XML UTF-8: #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
||||||
// but we use fast version
|
// but we use fast version
|
||||||
|
BIN
styles.png
BIN
styles.png
Binary file not shown.
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 52 KiB |
Loading…
Reference in New Issue
Block a user