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