Repository navigation
Expand file tree
/
Copy pathXMLWriter.php
More file actions
114 lines (107 loc) · 3.28 KB
/
Copy pathXMLWriter.php
File metadata and controls
114 lines (107 loc) · 3.28 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Faisalman\SimpleExcel\Writer;
use Faisalman\SimpleExcel\Enums\Datatype;
/**
* SimpleExcel class for writing Microsoft Excel 2003 XML Spreadsheet
*
* @author Faisal Salman
* @package Faisalman\SimpleExcel
*/
class XMLWriter extends BaseWriter
{
/**
* Defines content-type for HTTP header
*
* @access protected
* @var string
*/
protected $content_type = 'application/xml';
/**
* Defines file extension to be used when saving file
*
* @access protected
* @var string
*/
protected $file_extension = 'xml';
/**
* Array containing document properties
*
* @access private
* @var array
*/
private $doc_prop;
/**
* @param Workbook reference to workbook
* @return void
*/
public function __construct(&$workbook){
parent::__construct($workbook);
$this->doc_prop = array(
'Author' => 'SimpleExcel.php',
'Company' => 'SimpleExcel.php',
'Created' => gmdate("Y-m-d\TH:i:s\Z"),
'Keywords' => 'SimpleExcel.php',
'LastAuthor' => 'SimpleExcel.php'
);
}
/**
* Get document content as string
*
* @param array $options Options
* @return string Content of document
*/
public function toString ($options = NULL) {
$properties = isset($options['properties']) ? $options['properties'] : $this->doc_prop;
$content = '<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">';
foreach ($properties as $propname => $propval) {
$content .= '
<'.$propname.'>'.$propval.'</'.$propname.'>';
}
$content .= '
</DocumentProperties>';
foreach ($this->workbook->getWorksheets() as $i => $worksheet) {
$content .= '
<Worksheet ss:Name="Sheet' . ($i + 1) . '">
<Table>';
foreach ($worksheet->getRecords() as $record) {
$content .= '
<Row>';
foreach ($record as $cell) {
$datatype = 'String';
switch ($cell->datatype) {
case Datatype::NUMBER:
$datatype = 'Number';
break;
case Datatype::LOGICAL:
$datatype = 'Boolean';
break;
case Datatype::DATETIME:
$datatype = 'DateTime';
break;
case Datatype::ERROR:
$datatype = 'Error';
}
$content .= '
<Cell>
<Data ss:Type="' . $datatype . '">' . $cell->value . '</Data>
</Cell>';
}
$content .= '
</Row>';
}
$content .= '
</Table>
</Worksheet>';
}
$content .= '
</Workbook>';
return $content;
}
}