1
0
mirror of https://github.com/shuchkin/simplexlsxgen.git synced 2023-08-10 21:12:59 +03:00

13 Commits

Author SHA1 Message Date
c78750ffe7 1.3.15 2023-04-19 14:27:21 +06:00
9cdb08ee98 Merge pull request #110 from DevOlegKosarev/master
add set meta data file
2023-04-19 14:19:46 +06:00
32276c4486 Merge branch 'master' of https://github.com/DevOlegKosarev/simplexlsxgen 2023-04-19 02:38:24 -05:00
3646e702ae * escape strings
* use fluid interface and '
+ Add LastModifiedBy
+ author, company, manager, LastModifiedBy set email
2023-04-19 02:38:08 -05:00
81120e6f72 * escape strings
* use fluid interface and '
+ Add LastModifiedBy
+ author, company, manager, LastModifiedBy set email
2023-04-19 02:31:58 -05:00
c449813bb1 Update SimpleXLSXGen.php
Fix 345 line $this->application
2023-04-19 01:57:19 -05:00
4f4ac11dae add set meta data file 2023-04-19 01:00:22 -05:00
1fa442f667 1.3.14 2023-04-18 22:54:48 +06:00
1ee4e5eb50 1.3.13 RTL 2023-04-12 15:24:17 +06:00
e02d764d0d 1.3.13 RTL 2023-04-11 03:18:46 +06:00
f65e57c735 Merge pull request #105 from xaviermdq/master
frozen panes correction and other formatting minimal corrections
2023-04-03 11:35:31 +06:00
4f3d09925c Update SimpleXLSXGen.php 2023-04-02 19:48:51 -03:00
95da6b5c05 Update SimpleXLSXGen.php 2023-04-02 19:03:38 -03:00
3 changed files with 223 additions and 123 deletions

View File

@ -1,9 +1,17 @@
# Changelog # Changelog
## 1.3.15 (2023-04-19)
* added meta: setTitle, setSubject, setAuthor, setCompany, setManager, setKeywords, setDescription, setCategory, setApplication, setLastModifiedBy. Thx [Oleg Kosarev](https://github.com/DevOlegKosarev)
## 1.3.14 (2023-04-18)
* fixed "This action doesn't work on multiple selection" error
## 1.3.13 (2023-04-11)
* ```$xlsx->rightToLeft()``` - RTL mode. Column A is on the far right, Column B is one column left of Column A, and so on. Also, information in cells is displayed in the Right to Left format.
## 1.3.12 (2023-03-31) ## 1.3.12 (2023-03-31)
* ```<style font-size="32">Big Text</style>``` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson) * ```<style font-size="32">Big Text</style>``` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson)
## 1.3.11 (2023-03-28) ## 1.3.11 (2023-03-28)
* freezePanes( corner_cell ) - freezePanes to keep an area of a worksheet visible while you scroll, corner_cell is not included, thx [Javier](https://github.com/xaviermdq) * freezePanes( corner_cell ) - freezePanes to keep an area of a worksheet visible while you scroll, corner_cell is not included, thx [Javier](https://github.com/xaviermdq)

View File

@ -138,6 +138,22 @@ $xlsx->autoFilter('A1:B10');
// the row and column of the indicated cell // the row and column of the indicated cell
$xlsx->freezePanes('C3'); $xlsx->freezePanes('C3');
// RTL mode
// Column A is on the far right, Column B is one column left of Column A, and so on. Also, information in cells is displayed in the Right to Left format.
$xlsx->rightToLeft();
// Set Meta Data Files
// this data in propertis Files and Info file in Office
$xlsx->setAuthor('Sergey Shuchkin <sergey.shuchkin@gmail.com>')
->setCompany('Microsoft <info@microsoft.com>')
->setManager('Bill Gates <bill.gates@microsoft.com>')
->setLastModifiedBy("Sergey Shuchkin <sergey.shuchkin@gmail.com>")
->setTitle('This is Title')
->setSubject('This is Subject')
->setKeywords('Keywords1, Keywords2, Keywords3, KeywordsN')
->setDescription('This is Description')
->setCategory('This is Сategory')
->setApplication('Shuchkin\SimpleXLSXGen')
``` ```
### JS array to Excel (AJAX) ### JS array to Excel (AJAX)
```php ```php

View File

@ -1,4 +1,6 @@
<?php /** @noinspection ReturnTypeCanBeDeclaredInspection */ <?php
/** @noinspection ReturnTypeCanBeDeclaredInspection */
/** @noinspection PhpMissingReturnTypeInspection */ /** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection NullCoalescingOperatorCanBeUsedInspection */ /** @noinspection NullCoalescingOperatorCanBeUsedInspection */
@ -13,10 +15,10 @@ namespace Shuchkin;
*/ */
class SimpleXLSXGen class SimpleXLSXGen
{ {
public $curSheet; public $curSheet;
protected $defaultFont; protected $defaultFont;
protected $defaultFontSize; protected $defaultFontSize;
protected $rtl;
protected $sheets; protected $sheets;
protected $template; protected $template;
protected $NF; // numFmts protected $NF; // numFmts
@ -27,6 +29,17 @@ class SimpleXLSXGen
protected $SI; // shared strings protected $SI; // shared strings
protected $SI_KEYS; protected $SI_KEYS;
protected $extLinkId; protected $extLinkId;
protected $title;
protected $subject;
protected $author;
protected $company;
protected $manager;
protected $description;
protected $application;
protected $keywords;
protected $category;
protected $lastModifiedBy;
const N_NORMAL = 0; // General const N_NORMAL = 0; // General
const N_INT = 1; // 0 const N_INT = 1; // 0
const N_DEC = 2; // 0.00 const N_DEC = 2; // 0.00
@ -78,9 +91,21 @@ class SimpleXLSXGen
public function __construct() public function __construct()
{ {
$this->subject = '';
$this->title = '';
$this->author = 'Sergey Shuchkin <sergey.shuchkin@gmail.com>';
$this->company = 'Sergey Shuchkin <sergey.shuchkin@gmail.com>';
$this->manager = 'Sergey Shuchkin <sergey.shuchkin@gmail.com>';
$this->description = '';
$this->keywords = '';
$this->category = '';
$this->lastModifiedBy = 'Sergey Shuchkin <sergey.shuchkin@gmail.com>';
$this->application = __CLASS__;
$this->curSheet = -1; $this->curSheet = -1;
$this->defaultFont = 'Calibri'; $this->defaultFont = 'Calibri';
$this->defaultFontSize = 10; $this->defaultFontSize = 10;
$this->rtl = false;
$this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']]; $this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']];
$this->extLinkId = 0; $this->extLinkId = 0;
$this->SI = []; // sharedStrings index $this->SI = []; // sharedStrings index
@ -111,15 +136,12 @@ class SimpleXLSXGen
self::B_SLANT_DASH_DOT => 'slantDashDot' self::B_SLANT_DASH_DOT => 'slantDashDot'
]; ];
$this->XF = [ // styles 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size $this->XF = [ // styles 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size
[self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_NONE, 0, 0, '', 0], [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_NONE, 0, 0, '', 0],
[self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_GRAY_125, 0, 0, '', 0], // hack [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_GRAY_125, 0, 0, '', 0], // hack
]; ];
$this->XF_KEYS[implode('-', $this->XF[0])] = 0; // & keys $this->XF_KEYS[implode('-', $this->XF[0])] = 0; // & keys
$this->XF_KEYS[implode('-', $this->XF[1])] = 1; $this->XF_KEYS[implode('-', $this->XF[1])] = 1;
$this->template = [ $this->template = [
'_rels/.rels' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> '_rels/.rels' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
@ -130,22 +152,36 @@ class SimpleXLSXGen
'docProps/app.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 'docProps/app.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"> <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
<TotalTime>0</TotalTime> <TotalTime>0</TotalTime>
<Application>' . __CLASS__ . '</Application></Properties>', <Application>{APP}</Application>
<Company>{COMPANY}</Company>
<Manager>{MANAGER}</Manager>
</Properties>',
'docProps/core.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 'docProps/core.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dcterms:created xsi:type="dcterms:W3CDTF">{DATE}</dcterms:created> <dcterms:created xsi:type="dcterms:W3CDTF">{DATE}</dcterms:created>
<dc:language>en-US</dc:language> <dc:title>{TITLE}</dc:title>
<dc:subject>{SUBJECT}</dc:subject>
<dc:creator>{AUTHOR}</dc:creator>
<cp:lastModifiedBy>{LAST_MODIFY_BY}</cp:lastModifiedBy>
<cp:keywords>{KEYWORD}</cp:keywords>
<dc:description>{DESCRIPTION}</dc:description>
<cp:category>{CATEGORY}</cp:category>
<dc:language>en-US</dc:language>
<dcterms:modified xsi:type="dcterms:W3CDTF">{DATE}</dcterms:modified> <dcterms:modified xsi:type="dcterms:W3CDTF">{DATE}</dcterms:modified>
<cp:revision>1</cp:revision> <cp:revision>1</cp:revision>
</cp:coreProperties>', </cp:coreProperties>',
'xl/_rels/workbook.xml.rels' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 'xl/_rels/workbook.xml.rels' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/> {RELS}
{SHEETS}', </Relationships>',
'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}"/>
><dimension ref="{REF}"/>{COLS}<sheetData>{ROWS}</sheetData>{AUTOFILTER}{MERGECELLS}{HYPERLINKS}</worksheet>', {SHEETVIEWS}
{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"?>
@ -158,15 +194,15 @@ class SimpleXLSXGen
{BORDERS} {BORDERS}
<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" /></cellStyleXfs> <cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" /></cellStyleXfs>
{XF} {XF}
<cellStyles count="1"> <cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>
<cellStyle name="Normal" xfId="0" builtinId="0"/>
</cellStyles>
</styleSheet>', </styleSheet>',
'xl/workbook.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 'xl/workbook.xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<fileVersion appName="' . __CLASS__ . '"/><sheets> <fileVersion appName="{APP}"/>
<sheets>
{SHEETS} {SHEETS}
</sheets></workbook>', </sheets>
</workbook>',
'[Content_Types].xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> '[Content_Types].xml' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Override PartName="/rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/> <Override PartName="/rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
@ -179,7 +215,6 @@ class SimpleXLSXGen
{TYPES} {TYPES}
</Types>', </Types>',
]; ];
// <col min="1" max="1" width="22.1796875" bestFit="1" customWidth="1"/> // <col min="1" max="1" width="22.1796875" bestFit="1" customWidth="1"/>
// <row r="1" spans="1:2" x14ac:dyDescent="0.35"><c r="A1" t="s"><v>0</v></c><c r="B1"><v>100</v></c></row><row r="2" spans="1:2" x14ac:dyDescent="0.35"><c r="A2" t="s"><v>1</v></c><c r="B2"><v>200</v></c></row> // <row r="1" spans="1:2" x14ac:dyDescent="0.35"><c r="A1" t="s"><v>0</v></c><c r="B1"><v>100</v></c></row><row r="2" spans="1:2" x14ac:dyDescent="0.35"><c r="A2" t="s"><v>1</v></c><c r="B2"><v>200</v></c></row>
// <si><t>Простой шаблон</t></si><si><t>Будем делать генератор</t></si> // <si><t>Простой шаблон</t></si><si><t>Будем делать генератор</t></si>
@ -192,7 +227,6 @@ class SimpleXLSXGen
public function addSheet(array $rows, $name = null) public function addSheet(array $rows, $name = null)
{ {
$this->curSheet++; $this->curSheet++;
if ($name === null) { // autogenerated sheet names if ($name === null) { // autogenerated sheet names
$name = 'Sheet' . ($this->curSheet + 1); $name = 'Sheet' . ($this->curSheet + 1);
@ -215,9 +249,7 @@ class SimpleXLSXGen
} }
} }
} }
$this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '', 'frozen' => '']; $this->sheets[$this->curSheet] = ['name' => $name, 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '', 'frozen' => ''];
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;
} else { } else {
@ -232,14 +264,12 @@ class SimpleXLSXGen
if (!$fh) { if (!$fh) {
return ''; return '';
} }
if (!$this->_write($fh)) { if (!$this->_write($fh)) {
fclose($fh); fclose($fh);
return ''; return '';
} }
$size = ftell($fh); $size = ftell($fh);
fseek($fh, 0); fseek($fh, 0);
return (string)fread($fh, $size); return (string)fread($fh, $size);
} }
@ -254,7 +284,6 @@ class SimpleXLSXGen
return false; return false;
} }
fclose($fh); fclose($fh);
return true; return true;
} }
@ -269,65 +298,67 @@ class SimpleXLSXGen
if (!$fh) { if (!$fh) {
return false; return false;
} }
if (!$this->_write($fh)) { if (!$this->_write($fh)) {
fclose($fh); fclose($fh);
return false; return false;
} }
$size = ftell($fh); $size = ftell($fh);
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', time())); header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', time()));
header('Content-Length: ' . $size); header('Content-Length: ' . $size);
while (ob_get_level()) { while (ob_get_level()) {
ob_end_clean(); ob_end_clean();
} }
fseek($fh, 0); fseek($fh, 0);
fpassthru($fh); fpassthru($fh);
fclose($fh); fclose($fh);
return true; return true;
} }
protected function _write($fh) protected function _write($fh)
{ {
$dirSignatureE = "\x50\x4b\x05\x06"; // end of central dir signature $dirSignatureE = "\x50\x4b\x05\x06"; // end of central dir signature
$zipComments = 'Generated by ' . __CLASS__ . ' PHP class, thanks sergey.shuchkin@gmail.com'; $zipComments = 'Generated by ' . __CLASS__ . ' PHP class, thanks sergey.shuchkin@gmail.com';
if (!$fh) { if (!$fh) {
return false; return false;
} }
$cdrec = ''; // central directory content $cdrec = ''; // central directory content
$entries = 0; // number of zipped files $entries = 0; // number of zipped files
$cnt_sheets = count($this->sheets); $cnt_sheets = count($this->sheets);
foreach ($this->template as $cfilename => $template) { foreach ($this->template as $cfilename => $template) {
if ($cfilename === 'xl/_rels/workbook.xml.rels') { if ($cfilename === 'xl/_rels/workbook.xml.rels') {
$s = ''; $s = '';
for ($i = 0; $i < $cnt_sheets; $i++) { for ($i = 0; $i < $cnt_sheets; $i++) {
$s .= '<Relationship Id="rId' . ($i + 2) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"' . $s .= '<Relationship Id="rId' . ($i + 1) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"' .
' Target="worksheets/sheet' . ($i + 1) . ".xml\"/>\n"; ' Target="worksheets/sheet' . ($i + 1) . ".xml\"/>\r\n";
} }
$s .= '<Relationship Id="rId' . ($i + 2) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/></Relationships>'; $s .= '<Relationship Id="rId' . ($i + 1) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>' . "\r\n";
$template = str_replace('{SHEETS}', $s, $template); $s .= '<Relationship Id="rId' . ($i + 2) . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>';
$template = str_replace('{RELS}', $s, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template); $this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++; $entries++;
} elseif ($cfilename === 'xl/workbook.xml') { } elseif ($cfilename === 'xl/workbook.xml') {
$s = ''; $s = '';
foreach ($this->sheets as $k => $v) { foreach ($this->sheets as $k => $v) {
$s .= '<sheet name="' . $this->esc($v['name']) . '" sheetId="' . ($k + 1) . '" state="visible" r:id="rId' . ($k + 2) . '"/>'; $s .= '<sheet name="' . $this->esc($v['name']) . '" sheetId="' . ($k + 1) . '" r:id="rId' . ($k + 1) . '"/>';
} }
$template = str_replace('{SHEETS}', $s, $template); $search = ['{SHEETS}', '{APP}'];
$replace = [$s, $this->esc($this->application)];
$template = str_replace($search, $replace, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
} elseif ($cfilename === 'docProps/app.xml') {
$search = ['{APP}', '{COMPANY}', '{MANAGER}'];
$replace = [$this->esc($this->application), $this->esc($this->company), $this->esc($this->manager)];
$template = str_replace($search, $replace, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template); $this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++; $entries++;
} elseif ($cfilename === 'docProps/core.xml') { } elseif ($cfilename === 'docProps/core.xml') {
$template = str_replace('{DATE}', gmdate('Y-m-d\TH:i:s\Z'), $template); $search = ['{DATE}', '{AUTHOR}', '{TITLE}', '{SUBJECT}', '{KEYWORD}', '{DESCRIPTION}', '{CATEGORY}', '{LAST_MODIFY_BY}'];
$replace = [gmdate('Y-m-d\TH:i:s\Z'), $this->esc($this->author), $this->esc($this->title), $this->esc($this->subject), $this->esc($this->keywords), $this->esc($this->description), $this->esc($this->category), $this->esc($this->lastModifiedBy)];
$template = str_replace($search, $replace, $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template); $this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++; $entries++;
} elseif ($cfilename === 'xl/sharedStrings.xml') { } elseif ($cfilename === 'xl/sharedStrings.xml') {
@ -363,12 +394,10 @@ class SimpleXLSXGen
} }
} }
$xml = null; $xml = null;
} elseif ($cfilename === '[Content_Types].xml') { } elseif ($cfilename === '[Content_Types].xml') {
$TYPES = ['<Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>']; $TYPES = ['<Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'];
foreach ($this->sheets as $k => $v) { foreach ($this->sheets as $k => $v) {
$TYPES[] = '<Override PartName="/xl/worksheets/sheet' . ($k + 1) . $TYPES[] = '<Override PartName="/xl/worksheets/sheet' . ($k + 1) . '.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>';
'.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>';
if ($this->extLinkId) { if ($this->extLinkId) {
$TYPES[] = '<Override PartName="/xl/worksheets/_rels/sheet' . ($k + 1) . '.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'; $TYPES[] = '<Override PartName="/xl/worksheets/_rels/sheet' . ($k + 1) . '.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>';
} }
@ -380,20 +409,17 @@ class SimpleXLSXGen
$NF = $XF = $FONTS = $F_KEYS = $FILLS = $FL_KEYS = []; $NF = $XF = $FONTS = $F_KEYS = $FILLS = $FL_KEYS = [];
$BR = ['<border><left/><right/><top/><bottom/><diagonal/></border>']; $BR = ['<border><left/><right/><top/><bottom/><diagonal/></border>'];
$BR_KEYS = [0 => 0]; $BR_KEYS = [0 => 0];
foreach ($this->NF as $k => $v) { foreach ($this->NF as $k => $v) {
$NF[] = '<numFmt numFmtId="' . $k . '" formatCode="' . htmlspecialchars($v, ENT_QUOTES) . '"/>'; $NF[] = '<numFmt numFmtId="' . $k . '" formatCode="' . htmlspecialchars($v, ENT_QUOTES) . '"/>';
} }
foreach ($this->XF as $xf) { foreach ($this->XF as $xf) {
// 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size // 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size
// fonts // fonts
$F_KEY = $xf[2] . '-' . $xf[4].'-'.$xf[7]; $F_KEY = $xf[2] . '-' . $xf[4] . '-' . $xf[7];
if (isset($F_KEYS[$F_KEY])) { if (isset($F_KEYS[$F_KEY])) {
$F_ID = $F_KEYS[$F_KEY]; $F_ID = $F_KEYS[$F_KEY];
} else { } else {
$F_ID = $F_KEYS[$F_KEY] = count($FONTS); $F_ID = $F_KEYS[$F_KEY] = count($FONTS);
$FONTS[] = '<font><name val="' . $this->defaultFont . '"/><family val="2"/>' $FONTS[] = '<font><name val="' . $this->defaultFont . '"/><family val="2"/>'
. ($xf[7] ? '<sz val="' . $xf[7] . '"/>' : '<sz val="' . $this->defaultFontSize . '"/>') . ($xf[7] ? '<sz val="' . $xf[7] . '"/>' : '<sz val="' . $this->defaultFontSize . '"/>')
. ($xf[2] & self::F_BOLD ? '<b/>' : '') . ($xf[2] & self::F_BOLD ? '<b/>' : '')
@ -421,13 +447,24 @@ class SimpleXLSXGen
. ($xf[3] & self::FL_COLOR ? '><fgColor rgb="' . $xf[5] . '"/><bgColor indexed="64"/></patternFill>' : ' />') . ($xf[3] & self::FL_COLOR ? '><fgColor rgb="' . $xf[5] . '"/><bgColor indexed="64"/></patternFill>' : ' />')
. '</fill>'; . '</fill>';
} }
$align = ($xf[1] & self::A_LEFT ? ' horizontal="left"' : '') $align = '';
. ($xf[1] & self::A_RIGHT ? ' horizontal="right"' : '') if ($xf[1] & self::A_LEFT) {
. ($xf[1] & self::A_CENTER ? ' horizontal="center"' : '') $align .= ' horizontal="left"';
. ($xf[1] & self::A_TOP ? ' vertical="top"' : '') } elseif ($xf[1] & self::A_RIGHT) {
. ($xf[1] & self::A_MIDDLE ? ' vertical="center"' : '') $align .= ' horizontal="right"';
. ($xf[1] & self::A_BOTTOM ? ' vertical="bottom"' : '') } elseif ($xf[1] & self::A_CENTER) {
. ($xf[1] & self::A_WRAPTEXT ? ' wrapText="1"' : ''); $align .= ' horizontal="center"';
}
if ($xf[1] & self::A_TOP) {
$align .= ' vertical="top"';
} elseif ($xf[1] & self::A_MIDDLE) {
$align .= ' vertical="center"';
} elseif ($xf[1] & self::A_BOTTOM) {
$align .= ' vertical="bottom"';
}
if ($xf[1] & self::A_WRAPTEXT) {
$align .= ' wrapText="1"';
}
// border // border
$BR_ID = 0; $BR_ID = 0;
@ -446,13 +483,12 @@ class SimpleXLSXGen
$ba[] = $ba[0]; $ba[] = $ba[0];
} }
if (!isset($ba[4])) { // diagonal if (!isset($ba[4])) { // diagonal
$ba[] = 'none'; $ba[] = 'none';
} }
$sides = [ 'left' => 3, 'right' => 1, 'top' => 0, 'bottom' => 2, 'diagonal' => 4]; $sides = ['left' => 3, 'right' => 1, 'top' => 0, 'bottom' => 2, 'diagonal' => 4];
foreach ($sides as $side => $idx) { foreach ($sides as $side => $idx) {
$s = 'thin'; $s = 'thin';
$c = ''; $c = '';
$va = explode('#', $ba[$idx]); $va = explode('#', $ba[$idx]);
if (isset($va[1])) { if (isset($va[1])) {
$s = $va[0] === '' ? 'thin' : $va[0]; $s = $va[0] === '' ? 'thin' : $va[0];
@ -465,7 +501,6 @@ class SimpleXLSXGen
if (strlen($c) === 6) { if (strlen($c) === 6) {
$c = 'FF' . $c; $c = 'FF' . $c;
} }
if ($s && $s !== 'none') { if ($s && $s !== 'none') {
$border .= '<' . $side . ' style="' . $s . '">' $border .= '<' . $side . ' style="' . $s . '">'
. '<color ' . ($c === '' ? 'auto="1"' : 'rgb="' . $c . '"') . '/>' . '<color ' . ($c === '' ? 'auto="1"' : 'rgb="' . $c . '"') . '/>'
@ -473,24 +508,18 @@ class SimpleXLSXGen
} else { } else {
$border .= '<' . $side . '/>'; $border .= '<' . $side . '/>';
} }
} }
$border .= '</border>'; $border .= '</border>';
$BR[] = $border; $BR[] = $border;
} }
} }
$XF[] = '<xf numFmtId="' . $xf[0] . '" fontId="' . $F_ID . '" fillId="' . $FL_ID . '" borderId="' . $BR_ID . '" xfId="0"' $XF[] = '<xf numFmtId="' . $xf[0] . '" fontId="' . $F_ID . '" fillId="' . $FL_ID . '" borderId="' . $BR_ID . '" xfId="0"'
. ($xf[0] > 0 ? ' applyNumberFormat="1"' : '') . ($xf[0] > 0 ? ' applyNumberFormat="1"' : '')
. ($F_ID > 0 ? ' applyFont="1"' : '') . ($F_ID > 0 ? ' applyFont="1"' : '')
. ($FL_ID > 0 ? ' applyFill="1"' : '') . ($FL_ID > 0 ? ' applyFill="1"' : '')
. ($BR_ID > 0 ? ' applyBorder="1"' : '') . ($BR_ID > 0 ? ' applyBorder="1"' : '')
. ($align ? ' applyAlignment="1"><alignment' . $align . '/></xf>' : '/>'); . ($align ? ' applyAlignment="1"><alignment' . $align . '/></xf>' : '/>');
} }
// wrap collections // wrap collections
array_unshift($NF, '<numFmts count="' . count($NF) . '">'); array_unshift($NF, '<numFmts count="' . count($NF) . '">');
$NF[] = '</numFmts>'; $NF[] = '</numFmts>';
@ -506,7 +535,8 @@ class SimpleXLSXGen
$template = str_replace( $template = str_replace(
['{NUMFMTS}', '{FONTS}', '{XF}', '{FILLS}', '{BORDERS}'], ['{NUMFMTS}', '{FONTS}', '{XF}', '{FILLS}', '{BORDERS}'],
[implode("\r\n", $NF), implode("\r\n", $FONTS), implode("\r\n", $XF), implode("\r\n", $FILLS), implode("\r\n", $BR)], [implode("\r\n", $NF), implode("\r\n", $FONTS), implode("\r\n", $XF), implode("\r\n", $FILLS), implode("\r\n", $BR)],
$template); $template
);
$this->_writeEntry($fh, $cdrec, $cfilename, $template); $this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++; $entries++;
} else { } else {
@ -516,7 +546,6 @@ class SimpleXLSXGen
} }
$before_cd = ftell($fh); $before_cd = ftell($fh);
fwrite($fh, $cdrec); fwrite($fh, $cdrec);
// end of central dir // end of central dir
fwrite($fh, $dirSignatureE); fwrite($fh, $dirSignatureE);
fwrite($fh, pack('v', 0)); // number of this disk fwrite($fh, pack('v', 0)); // number of this disk
@ -538,7 +567,6 @@ class SimpleXLSXGen
$e = []; $e = [];
$e['uncsize'] = mb_strlen($data, '8bit'); $e['uncsize'] = mb_strlen($data, '8bit');
// if data to compress is too small, just store it // if data to compress is too small, just store it
if ($e['uncsize'] < 256) { if ($e['uncsize'] < 256) {
$e['comsize'] = $e['uncsize']; $e['comsize'] = $e['uncsize'];
@ -552,7 +580,6 @@ class SimpleXLSXGen
$e['vneeded'] = 10; $e['vneeded'] = 10;
$e['cmethod'] = 8; $e['cmethod'] = 8;
} }
$e['bitflag'] = 0; $e['bitflag'] = 0;
$e['crc_32'] = crc32($data); $e['crc_32'] = crc32($data);
@ -566,7 +593,6 @@ class SimpleXLSXGen
$e['modtime'] = bindec("$lastmod_timeH$lastmod_timeM$lastmod_timeS"); $e['modtime'] = bindec("$lastmod_timeH$lastmod_timeM$lastmod_timeS");
$e['moddate'] = bindec("$lastmod_dateY$lastmod_dateM$lastmod_dateD"); $e['moddate'] = bindec("$lastmod_dateY$lastmod_dateM$lastmod_dateD");
$e['offset'] = ftell($fh); $e['offset'] = ftell($fh);
fwrite($fh, $zipSignature); fwrite($fh, $zipSignature);
@ -589,22 +615,22 @@ class SimpleXLSXGen
$e['comments'] = ''; $e['comments'] = '';
$cdrec .= $dirSignature; $cdrec .= $dirSignature;
$cdrec .= "\x0\x0"; // version made by $cdrec .= "\x0\x0"; // version made by
$cdrec .= pack('v', $e['vneeded']); // version needed to extract $cdrec .= pack('v', $e['vneeded']); // version needed to extract
$cdrec .= "\x0\x0"; // general bit flag $cdrec .= "\x0\x0"; // general bit flag
$cdrec .= pack('v', $e['cmethod']); // compression method $cdrec .= pack('v', $e['cmethod']); // compression method
$cdrec .= pack('v', $e['modtime']); // lastmod time $cdrec .= pack('v', $e['modtime']); // lastmod time
$cdrec .= pack('v', $e['moddate']); // lastmod date $cdrec .= pack('v', $e['moddate']); // lastmod date
$cdrec .= pack('V', $e['crc_32']); // crc32 $cdrec .= pack('V', $e['crc_32']); // crc32
$cdrec .= pack('V', $e['comsize']); // compressed filesize $cdrec .= pack('V', $e['comsize']); // compressed filesize
$cdrec .= pack('V', $e['uncsize']); // uncompressed filesize $cdrec .= pack('V', $e['uncsize']); // uncompressed filesize
$cdrec .= pack('v', mb_strlen($cfilename, '8bit')); // file name length $cdrec .= pack('v', mb_strlen($cfilename, '8bit')); // file name length
$cdrec .= pack('v', 0); // extra field length $cdrec .= pack('v', 0); // extra field length
$cdrec .= pack('v', mb_strlen($e['comments'], '8bit')); // file comment length $cdrec .= pack('v', mb_strlen($e['comments'], '8bit')); // file comment length
$cdrec .= pack('v', 0); // disk number start $cdrec .= pack('v', 0); // disk number start
$cdrec .= pack('v', 0); // internal file attributes $cdrec .= pack('v', 0); // internal file attributes
$cdrec .= pack('V', $e['external_attributes']); // internal file attributes $cdrec .= pack('V', $e['external_attributes']); // internal file attributes
$cdrec .= pack('V', $e['offset']); // relative offset of local header $cdrec .= pack('V', $e['offset']); // relative offset of local header
$cdrec .= $cfilename; $cdrec .= $cfilename;
$cdrec .= $e['comments']; $cdrec .= $e['comments'];
} }
@ -616,13 +642,16 @@ class SimpleXLSXGen
setlocale(LC_NUMERIC, 'C'); setlocale(LC_NUMERIC, 'C');
$COLS = []; $COLS = [];
$ROWS = []; $ROWS = [];
// $SHEETVIEWS = '<sheetViews><sheetView tabSelected="1" workbookViewId="0"'.($this->rtl ? ' rightToLeft="1"' : '').'>';
$SHEETVIEWS = ''; $SHEETVIEWS = '';
$PANE = '';
if (count($this->sheets[$idx]['rows'])) { if (count($this->sheets[$idx]['rows'])) {
if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) { if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) {
// $AC = 'A1'; // Active Cell
$x = $y = 0; $x = $y = 0;
if (is_string($this->sheets[$idx]['frozen'])) { if (is_string($this->sheets[$idx]['frozen'])) {
$cell = $this->sheets[$idx]['frozen']; $AC = $this->sheets[$idx]['frozen'];
self::cell2coord($cell, $x, $y); self::cell2coord($AC, $x, $y);
} else { } else {
if (isset($this->sheets[$idx]['frozen'][0])) { if (isset($this->sheets[$idx]['frozen'][0])) {
$x = $this->sheets[$idx]['frozen'][0]; $x = $this->sheets[$idx]['frozen'][0];
@ -630,26 +659,33 @@ class SimpleXLSXGen
if (isset($this->sheets[$idx]['frozen'][1])) { if (isset($this->sheets[$idx]['frozen'][1])) {
$y = $this->sheets[$idx]['frozen'][1]; $y = $this->sheets[$idx]['frozen'][1];
} }
$cell = self::coord2cell($x, $y); $AC = self::coord2cell($x, $y);
} }
if ($x > 0 || $y > 0) { if ($x > 0 || $y > 0) {
$split = ''; $split = '';
if ($x > 0) { if ($x > 0) {
$split .= ' xSplit="'.$x.'"'; $split .= ' xSplit="' . $x . '"';
} }
if ($y > 0) { if ($y > 0) {
$split .= ' ySplit="'.$y.'"'; $split .= ' ySplit="' . $y . '"';
} }
$activepane = 'bottomRight'; $activepane = 'bottomRight';
if ($x > 0 && $y === 0) { if ($x > 0 && $y === 0) {
$activepane = 'topRight'; $activepane = 'topRight';
} }
if ($x === 0 && $y > 0) { if ($x === 0 && $y > 0) {
$activepane = 'bottomLeft'; $activepane = 'bottomLeft';
} }
$SHEETVIEWS = '<sheetViews><sheetView tabSelected="1" workbookViewId="0"><pane'.$split.' topLeftCell="'.$cell.'" activePane="'.$activepane.'" state="frozen"/></sheetView></sheetViews>'; $PANE .= '<pane' . $split . ' topLeftCell="' . $AC . '" activePane="' . $activepane . '" state="frozen"/>';
$PANE .= '<selection activeCell="' . $AC . '" sqref="' . $AC . '"/>';
} }
} }
if ($this->rtl || $PANE) {
$SHEETVIEWS .= '<sheetViews>
<sheetView workbookViewId="0"' . ($this->rtl ? ' rightToLeft="1"' : '');
$SHEETVIEWS .= $PANE ? ">\r\n" . $PANE . "\r\n</sheetView>" : ' />';
$SHEETVIEWS .= "\r\n</sheetViews>";
}
$COLS[] = '<cols>'; $COLS[] = '<cols>';
$CUR_ROW = 0; $CUR_ROW = 0;
$COL = []; $COL = [];
@ -664,18 +700,14 @@ class SimpleXLSXGen
$COL[$CUR_COL] = 0; $COL[$CUR_COL] = 0;
} }
$cname = $this->num2name($CUR_COL) . $CUR_ROW; $cname = $this->num2name($CUR_COL) . $CUR_ROW;
if ($v === null || $v === '') { if ($v === null || $v === '') {
$row .= '<c r="' . $cname . '"/>'; $row .= '<c r="' . $cname . '"/>';
continue; continue;
} }
$ct = $cv = $cf = null; $ct = $cv = $cf = null;
$N = $A = $F = $FL = $C = $BG = $FS = 0; $N = $A = $F = $FL = $C = $BG = $FS = 0;
$BR = ''; $BR = '';
if (is_string($v)) { if (is_string($v)) {
if ($v[0] === "\0") { // RAW value as string if ($v[0] === "\0") { // RAW value as string
$v = substr($v, 1); $v = substr($v, 1);
$vl = mb_strlen($v); $vl = mb_strlen($v);
@ -694,9 +726,7 @@ class SimpleXLSXGen
$F += self::F_STRIKE; $F += self::F_STRIKE;
} }
if (preg_match('/<style([^>]+)>/', $v, $m)) { if (preg_match('/<style([^>]+)>/', $v, $m)) {
if (preg_match('/ color="([^"]+)"/', $m[1], $m2)) { if (preg_match('/ color="([^"]+)"/', $m[1], $m2)) {
$F += self::F_COLOR; $F += self::F_COLOR;
$c = ltrim($m2[1], '#'); $c = ltrim($m2[1], '#');
$C = strlen($c) === 8 ? $c : ('FF' . $c); $C = strlen($c) === 8 ? $c : ('FF' . $c);
@ -722,8 +752,8 @@ class SimpleXLSXGen
if (preg_match('/ font-size="([^"]+)"/', $m[1], $m2)) { if (preg_match('/ font-size="([^"]+)"/', $m[1], $m2)) {
$FS = (int)$m2[1]; $FS = (int)$m2[1];
if ($RH === 0) { // fix row height if ($RH === 0) { // fix row height
$RH = ($FS > $this->defaultFontSize) ? round($FS * 1.50,1) : 0; $RH = ($FS > $this->defaultFontSize) ? round($FS * 1.50, 1) : 0;
} }
} }
} }
if (strpos($v, '<left>') !== false) { if (strpos($v, '<left>') !== false) {
@ -834,9 +864,7 @@ class SimpleXLSXGen
} }
} }
if ($cv === null) { if ($cv === null) {
$v = $this->esc($v); $v = $this->esc($v);
if ($cf) { if ($cf) {
$ct = 'str'; $ct = 'str';
$cv = $v; $cv = $v;
@ -870,13 +898,9 @@ class SimpleXLSXGen
} else { } else {
continue; continue;
} }
$COL[$CUR_COL] = max($vl, $COL[$CUR_COL]); $COL[$CUR_COL] = max($vl, $COL[$CUR_COL]);
$cs = 0; $cs = 0;
if (($N + $A + $F + $FL + $FS > 0) || $BR !== '') { if (($N + $A + $F + $FL + $FS > 0) || $BR !== '') {
if ($FL === self::FL_COLOR) { if ($FL === self::FL_COLOR) {
$FL += self::FL_SOLID; $FL += self::FL_SOLID;
} }
@ -884,7 +908,6 @@ class SimpleXLSXGen
$F += self::F_COLOR; $F += self::F_COLOR;
$C = 'FF0563C1'; $C = 'FF0563C1';
} }
$XF_KEY = $N . '-' . $A . '-' . $F . '-' . $FL . '-' . $C . '-' . $BG . '-' . $BR . '-' . $FS; $XF_KEY = $N . '-' . $A . '-' . $F . '-' . $FL . '-' . $C . '-' . $BG . '-' . $BR . '-' . $FS;
if (isset($this->XF_KEYS[$XF_KEY])) { if (isset($this->XF_KEYS[$XF_KEY])) {
$cs = $this->XF_KEYS[$XF_KEY]; $cs = $this->XF_KEYS[$XF_KEY];
@ -895,7 +918,6 @@ class SimpleXLSXGen
$this->XF[] = [$N, $A, $F, $FL, $C, $BG, $BR, $FS]; $this->XF[] = [$N, $A, $F, $FL, $C, $BG, $BR, $FS];
} }
} }
$row .= '<c r="' . $cname . '"' . ($ct ? ' t="' . $ct . '"' : '') . ($cs ? ' s="' . $cs . '"' : '') . '>' $row .= '<c r="' . $cname . '"' . ($ct ? ' t="' . $ct . '"' : '') . ($cs ? ' s="' . $cs . '"' : '') . '>'
. ($cf ? '<f>' . $cf . '</f>' : '') . ($cf ? '<f>' . $cf . '</f>' : '')
. ($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";
@ -940,7 +962,8 @@ class SimpleXLSXGen
//restore locale //restore locale
setlocale(LC_NUMERIC, $_loc); setlocale(LC_NUMERIC, $_loc);
return str_replace(['{REF}', '{COLS}', '{ROWS}', '{AUTOFILTER}', '{MERGECELLS}', '{HYPERLINKS}', '{SHEETVIEWS}'], return str_replace(
['{REF}', '{COLS}', '{ROWS}', '{AUTOFILTER}', '{MERGECELLS}', '{HYPERLINKS}', '{SHEETVIEWS}'],
[ [
$REF, $REF,
implode("\r\n", $COLS), implode("\r\n", $COLS),
@ -950,7 +973,8 @@ class SimpleXLSXGen
implode("\r\n", $HYPERLINKS), implode("\r\n", $HYPERLINKS),
$SHEETVIEWS $SHEETVIEWS
], ],
$template); $template
);
} }
public function num2name($num) public function num2name($num)
@ -966,20 +990,16 @@ class SimpleXLSXGen
public function date2excel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0) public function date2excel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
{ {
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400; $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
if ((int)$year === 0) { if ((int)$year === 0) {
return $excelTime; return $excelTime;
} }
// self::CALENDAR_WINDOWS_1900 // self::CALENDAR_WINDOWS_1900
$excel1900isLeapYear = True; $excel1900isLeapYear = True;
if (($year === 1900) && ($month <= 2)) { if (($year === 1900) && ($month <= 2)) {
$excel1900isLeapYear = False; $excel1900isLeapYear = False;
} }
$myExcelBaseDate = 2415020; $myExcelBaseDate = 2415020;
// Julian base date Adjustment // Julian base date Adjustment
if ($month > 2) { if ($month > 2) {
$month -= 3; $month -= 3;
@ -991,7 +1011,6 @@ class SimpleXLSXGen
$decade = substr($year, 2, 2); $decade = substr($year, 2, 2);
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0) // Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear; $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear;
return (float)$excelDate + $excelTime; return (float)$excelDate + $excelTime;
} }
@ -1007,6 +1026,58 @@ class SimpleXLSXGen
return $this; return $this;
} }
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function setSubject($subject)
{
$this->subject = $subject;
return $this;
}
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
public function setCompany($company)
{
$this->company = $company;
return $this;
}
public function setManager($manager)
{
$this->manager = $manager;
return $this;
}
public function setKeywords($keywords)
{
$this->keywords = $keywords;
return $this;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function setCategory($category)
{
$this->category = $category;
return $this;
}
public function setApplication($application)
{
$this->application = $application;
return $this;
}
public function setLastModifiedBy($lastModifiedBy)
{
$this->lastModifiedBy = $lastModifiedBy;
return $this;
}
public function autoFilter($range) public function autoFilter($range)
{ {
$this->sheets[$this->curSheet]['autofilter'] = $range; $this->sheets[$this->curSheet]['autofilter'] = $range;
@ -1024,6 +1095,11 @@ class SimpleXLSXGen
$this->sheets[$this->curSheet]['colwidth'][$col] = $width; $this->sheets[$this->curSheet]['colwidth'][$col] = $width;
return $this; return $this;
} }
public function rightToLeft($value = true)
{
$this->rtl = $value;
return $this;
}
public function esc($str) public function esc($str)
{ {
@ -1046,6 +1122,7 @@ class SimpleXLSXGen
return $id; return $id;
} }
public static function raw($value) public static function raw($value)
{ {
return "\0" . $value; return "\0" . $value;
@ -1068,8 +1145,8 @@ class SimpleXLSXGen
if ($lettercount > 0) { if ($lettercount > 0) {
$x = ord($cell[$lettercount - 1]) - ord('A'); $x = ord($cell[$lettercount - 1]) - ord('A');
$e = 1; $e = 1;
for ($i = $lettercount - 2 ; $i >= 0 ; $i--) { for ($i = $lettercount - 2; $i >= 0; $i--) {
$x += (ord($cell[$i]) - ord('A') + 1) * (26**$e); $x += (ord($cell[$i]) - ord('A') + 1) * (26 ** $e);
$e++; $e++;
} }
} }
@ -1078,13 +1155,13 @@ class SimpleXLSXGen
} }
} }
public static function coord2cell($x, $y, $absolute = false) public static function coord2cell($x, $y)
{ {
$c = ''; $c = '';
for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) { for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) {
$c = chr(ord('A') + $i % 26) . $c; $c = chr(ord('A') + $i % 26) . $c;
} }
return ($absolute ? '$' : '') . $c . $absolute . ($y+1); return $c . ($y + 1);
} }
public function freezePanes($cell) public function freezePanes($cell)
@ -1092,5 +1169,4 @@ class SimpleXLSXGen
$this->sheets[$this->curSheet]['frozen'] = $cell; $this->sheets[$this->curSheet]['frozen'] = $cell;
return $this; return $this;
} }
} }