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

add set meta data file

This commit is contained in:
Oleg Kosarev 2023-04-19 01:00:22 -05:00
parent 1fa442f667
commit 4f4ac11dae
2 changed files with 122 additions and 21 deletions

View File

@ -142,6 +142,17 @@ $xlsx->freezePanes('C3');
// 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. // 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(); $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")
``` ```
### 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 */
@ -27,6 +29,16 @@ 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;
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,6 +90,16 @@ class SimpleXLSXGen
public function __construct() public function __construct()
{ {
$this->subject = '';
$this->title = '';
$this->author = 'Sergey Shuchkin';
$this->company = 'Sergey Shuchkin';
$this->manager = 'Sergey Shuchkin';
$this->description = '';
$this->keywords = '';
$this->category = '';
$this->application = __CLASS__;
$this->curSheet = -1; $this->curSheet = -1;
$this->defaultFont = 'Calibri'; $this->defaultFont = 'Calibri';
$this->defaultFontSize = 10; $this->defaultFontSize = 10;
@ -118,7 +140,6 @@ class SimpleXLSXGen
]; ];
$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">
@ -129,11 +150,19 @@ 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> <Application>{APP}</Application>
<Company>{COMPANY}</Company>
<Manager>{MANAGER}</Manager>
</Properties>', </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:title>{TITLE}</dc:title>
<dc:subject>{SUBJECT}</dc:subject>
<dc:creator>{AUTHOR}</dc:creator>
<cp:keywords>{KEYWORD}</cp:keywords>
<dc:description>{DESCRIPTION}</dc:description>
<cp:category>{CATEGORY}</cp:category>
<dc:language>en-US</dc:language> <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>
@ -166,7 +195,7 @@ class SimpleXLSXGen
</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__ . '"/> <fileVersion appName="{APP}"/>
<sheets> <sheets>
{SHEETS} {SHEETS}
</sheets> </sheets>
@ -312,11 +341,21 @@ class SimpleXLSXGen
foreach ($this->sheets as $k => $v) { foreach ($this->sheets as $k => $v) {
$s .= '<sheet name="' . $this->esc($v['name']) . '" sheetId="' . ($k + 1) . '" r:id="rId' . ($k + 1) . '"/>'; $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->template];
$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];
$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}'];
$replace = [gmdate('Y-m-d\TH:i:s\Z'), $this->author, $this->title, $this->subject, $this->keywords, $this->description, $this->category];
$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') {
@ -514,6 +553,7 @@ class SimpleXLSXGen
fwrite($fh, pack('V', $before_cd)); // offset to start of central dir fwrite($fh, pack('V', $before_cd)); // offset to start of central dir
fwrite($fh, pack('v', mb_strlen($zipComments, '8bit'))); // .zip file comment length fwrite($fh, pack('v', mb_strlen($zipComments, '8bit'))); // .zip file comment length
fwrite($fh, $zipComments); fwrite($fh, $zipComments);
return true; return true;
} }
@ -919,7 +959,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),
@ -929,7 +970,8 @@ class SimpleXLSXGen
implode("\r\n", $HYPERLINKS), implode("\r\n", $HYPERLINKS),
$SHEETVIEWS $SHEETVIEWS
], ],
$template); $template
);
} }
public function num2name($num) public function num2name($num)
@ -981,6 +1023,53 @@ 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 autoFilter($range) public function autoFilter($range)
{ {
$this->sheets[$this->curSheet]['autofilter'] = $range; $this->sheets[$this->curSheet]['autofilter'] = $range;
@ -998,7 +1087,8 @@ 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) { public function rightToLeft($value = true)
{
$this->rtl = $value; $this->rtl = $value;
return $this; return $this;
} }