30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../../');
38 require_once PHPEXCEL_ROOT .
'PHPExcel/Writer/Excel2007.php';
41 require_once PHPEXCEL_ROOT .
'PHPExcel/Writer/Excel2007/WriterPart.php';
44 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell/DataType.php';
47 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/XMLWriter.php';
50 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/String.php';
72 if (!is_null($pSheet)) {
74 $aStringTable = array();
75 $cellCollection = null;
76 $aFlippedStringTable = null;
79 if (!is_null($pExistingTable) && is_array($pExistingTable)) {
80 $aStringTable = $pExistingTable;
87 $cellCollection = $pSheet->getCellCollection();
88 foreach ($cellCollection as $cell) {
89 if (!is_object($cell->getValue()) &&
90 !isset($aFlippedStringTable[$cell->getValue()]) &&
91 !is_null($cell->getValue()) &&
92 $cell->getValue() !==
'' &&
95 $aStringTable[] = $cell->getValue();
96 $aFlippedStringTable[$cell->getValue()] = 1;
99 !isset($aFlippedStringTable[$cell->getValue()->getHashCode()]) &&
100 !is_null($cell->getValue())
102 $aStringTable[] = $cell->getValue();
103 $aFlippedStringTable[$cell->getValue()->getHashCode()] = 1;
108 return $aStringTable;
110 throw new Exception(
"Invalid PHPExcel_Worksheet object passed.");
123 if (!is_null($pStringTable)) {
133 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
136 $objWriter->startElement(
'sst');
137 $objWriter->writeAttribute(
'xmlns',
'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
138 $objWriter->writeAttribute(
'uniqueCount', count($pStringTable));
141 foreach ($pStringTable as $textElement) {
142 $objWriter->startElement(
'si');
146 $objWriter->startElement(
't');
147 if ($textToWrite !== trim($textToWrite)) {
148 $objWriter->writeAttribute(
'xml:space',
'preserve');
150 $objWriter->writeRaw($textToWrite);
151 $objWriter->endElement();
152 }
else if ($textElement instanceof PHPExcel_RichText) {
156 $objWriter->endElement();
159 $objWriter->endElement();
162 return $objWriter->getData();
164 throw new Exception(
"Invalid string table array passed.");
178 $elements = $pRichText->getRichTextElements();
179 foreach ($elements as $element) {
181 $objWriter->startElement(
'r');
186 $objWriter->startElement(
'rPr');
189 $objWriter->startElement(
'rFont');
190 $objWriter->writeAttribute(
'val', $element->getFont()->getName());
191 $objWriter->endElement();
194 $objWriter->startElement(
'b');
195 $objWriter->writeAttribute(
'val', ($element->getFont()->getBold() ?
'true' :
'false'));
196 $objWriter->endElement();
199 $objWriter->startElement(
'i');
200 $objWriter->writeAttribute(
'val', ($element->getFont()->getItalic() ?
'true' :
'false'));
201 $objWriter->endElement();
204 if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) {
205 $objWriter->startElement(
'vertAlign');
206 if ($element->getFont()->getSuperScript()) {
207 $objWriter->writeAttribute(
'val',
'superscript');
208 }
else if ($element->getFont()->getSubScript()) {
209 $objWriter->writeAttribute(
'val',
'subscript');
211 $objWriter->endElement();
215 $objWriter->startElement(
'strike');
216 $objWriter->writeAttribute(
'val', ($element->getFont()->getStrikethrough() ?
'true' :
'false'));
217 $objWriter->endElement();
220 $objWriter->startElement(
'color');
221 $objWriter->writeAttribute(
'rgb', $element->getFont()->getColor()->getARGB());
222 $objWriter->endElement();
225 $objWriter->startElement(
'sz');
226 $objWriter->writeAttribute(
'val', $element->getFont()->getSize());
227 $objWriter->endElement();
230 $objWriter->startElement(
'u');
231 $objWriter->writeAttribute(
'val', $element->getFont()->getUnderline());
232 $objWriter->endElement();
234 $objWriter->endElement();
238 $objWriter->startElement(
't');
239 $objWriter->writeAttribute(
'xml:space',
'preserve');
241 $objWriter->endElement();
243 $objWriter->endElement();
255 $returnValue = array();
258 foreach ($stringTable as
$key => $value) {
260 $returnValue[$value] =
$key;
261 }
else if ($value instanceof PHPExcel_RichText) {
262 $returnValue[$value->getHashCode()] =
$key;