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

* escape strings

* use fluid interface and '
+ Add LastModifiedBy
+ author, company, manager, LastModifiedBy set email
This commit is contained in:
Oleg Kosarev 2023-04-19 02:38:08 -05:00
parent c449813bb1
commit 3646e702ae
2 changed files with 26 additions and 16 deletions

View File

@ -144,15 +144,16 @@ $xlsx->rightToLeft();
// Set Meta Data Files
// this data in propertis Files and Info file in Office
$xlsx->setAuthor("Sergey Shuchkin")
$xlsx->setCompany("Sergey Shuchkin Company")
$xlsx->setManager("Sergey Shuchkin Manager")
$xlsx->setTitle("This is Title")
$xlsx->setSubject("This is Subject")
$xlsx->setKeywords("Keywords1, Keywords2, Keywords3, KeywordsN")
$xlsx->setDescription("This is Description")
$xlsx->setCategory("This is Сategory")
$xlsx->setApplication("This Is Best Application For Generate")
$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)
```php

View File

@ -39,6 +39,7 @@ class SimpleXLSXGen
protected $application;
protected $keywords;
protected $category;
protected $lastModifiedBy;
const N_NORMAL = 0; // General
const N_INT = 1; // 0
const N_DEC = 2; // 0.00
@ -92,12 +93,13 @@ class SimpleXLSXGen
{
$this->subject = '';
$this->title = '';
$this->author = 'Sergey Shuchkin';
$this->company = 'Sergey Shuchkin';
$this->manager = 'Sergey Shuchkin';
$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;
@ -160,6 +162,7 @@ class SimpleXLSXGen
<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>
@ -342,19 +345,19 @@ class SimpleXLSXGen
$s .= '<sheet name="' . $this->esc($v['name']) . '" sheetId="' . ($k + 1) . '" r:id="rId' . ($k + 1) . '"/>';
}
$search = ['{SHEETS}', '{APP}'];
$replace = [$s, $this->application];
$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->application, $this->company, $this->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);
$entries++;
} elseif ($cfilename === 'docProps/core.xml') {
$search = ['{DATE}', '{AUTHOR}', '{TITLE}', '{SUBJECT}', '{KEYWORD}', '{DESCRIPTION}', '{CATEGORY}'];
$replace = [gmdate('Y-m-d\TH:i:s\Z'), $this->author, $this->title, $this->subject, $this->keywords, $this->description, $this->category];
$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);
$entries++;
@ -1070,6 +1073,12 @@ class SimpleXLSXGen
return $this;
}
public function setLastModifiedBy($lastModifiedBy)
{
$this->lastModifiedBy = $lastModifiedBy;
return $this;
}
public function autoFilter($range)
{
$this->sheets[$this->curSheet]['autofilter'] = $range;