-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathContentTypes.php
82 lines (73 loc) · 2.87 KB
/
ContentTypes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Ellumilel;
/**
* @link https://msdn.microsoft.com/en-us/library/bb264572(v=office.12).aspx
*
* Class ContentTypes
* @package Ellumilel
* @author Denis Tikhonov <ozy@mailserver.ru>
*/
class ContentTypes
{
/** @var string */
private $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
/** @var string */
private $urlContentTypes = 'http://schemas.openxmlformats.org/package/2006/content-types';
/** @var bool */
private $sharedStringsRelations = false;
/** @var array */
private $sheets = [];
/**
* Relationships constructor.
*
* @param bool $sharedStringsRelations
*/
public function __construct($sharedStringsRelations = false)
{
$this->sharedStringsRelations = $sharedStringsRelations;
}
/**
* @param array $sheets
*
* @return $this
*/
public function setSheet(array $sheets)
{
$this->sheets = $sheets;
return $this;
}
/**
* @return string
*/
public function buildContentTypesXML()
{
$xml = '';
$xml .= $this->xml;
$xml .= '<Types xmlns="'.$this->urlContentTypes.'">';
$xml .= '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>';
$xml .= '<Default Extension="xml" ContentType="application/xml"/>';
$xml .= '<Override PartName="/_rels/.rels"';
$xml .= ' ContentType="application/vnd.openxmlformats-package.relationships+xml"/>';
$xml .= '<Override PartName="/xl/_rels/workbook.xml.rels"';
$xml .= ' ContentType="application/vnd.openxmlformats-package.relationships+xml"/>';
/** @var Sheet $sheet */
foreach ($this->sheets as $sheet) {
$xml .= '<Override PartName="/xl/worksheets/'.($sheet->getXmlName()).'"';
$xml .= ' ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>';
}
if ($this->sharedStringsRelations) {
$xml .= '<Override PartName="/xl/sharedStrings.xml"';
$xml .= ' ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>';
}
$xml .= '<Override PartName="/xl/workbook.xml"';
$xml .= ' ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>';
$xml .= '<Override PartName="/xl/styles.xml"';
$xml .= ' ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>';
$xml .= '<Override PartName="/docProps/app.xml"';
$xml .= ' ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>';
$xml .= '<Override PartName="/docProps/core.xml"';
$xml .= ' ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>'."\n";
$xml .= '</Types>';
return $xml;
}
}