26 $cellCollection = null;
27 $aFlippedStringTable = null;
30 if (($pExistingTable !== null) && is_array($pExistingTable)) {
31 $aStringTable = $pExistingTable;
39 $cell = $pSheet->getCell($coordinate);
40 $cellValue = $cell->getValue();
42 !is_object($cellValue) &&
43 ($cellValue !== null) &&
45 !isset($aFlippedStringTable[$cellValue]) &&
48 $aStringTable[] = $cellValue;
49 $aFlippedStringTable[$cellValue] =
true;
52 ($cellValue !== null) &&
53 !isset($aFlippedStringTable[$cellValue->getHashCode()])
55 $aStringTable[] = $cellValue;
56 $aFlippedStringTable[$cellValue->getHashCode()] =
true;
77 $objWriter =
new XMLWriter(XMLWriter::STORAGE_MEMORY);
81 $objWriter->startDocument(
'1.0',
'UTF-8',
'yes');
84 $objWriter->startElement(
'sst');
85 $objWriter->writeAttribute(
'xmlns',
'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
86 $objWriter->writeAttribute(
'uniqueCount', count($pStringTable));
89 foreach ($pStringTable as $textElement) {
90 $objWriter->startElement(
'si');
92 if (!$textElement instanceof
RichText) {
94 $objWriter->startElement(
't');
95 if ($textToWrite !== trim($textToWrite)) {
96 $objWriter->writeAttribute(
'xml:space',
'preserve');
98 $objWriter->writeRawData($textToWrite);
99 $objWriter->endElement();
100 } elseif ($textElement instanceof RichText) {
104 $objWriter->endElement();
107 $objWriter->endElement();
109 return $objWriter->getData();
121 if ($prefix !== null) {
127 foreach ($elements as $element) {
129 $objWriter->startElement($prefix .
'r');
132 if ($element instanceof
Run) {
134 $objWriter->startElement($prefix .
'rPr');
137 $objWriter->startElement($prefix .
'rFont');
138 $objWriter->writeAttribute(
'val', $element->getFont()->getName());
139 $objWriter->endElement();
142 $objWriter->startElement($prefix .
'b');
143 $objWriter->writeAttribute(
'val', ($element->getFont()->getBold() ?
'true' :
'false'));
144 $objWriter->endElement();
147 $objWriter->startElement($prefix .
'i');
148 $objWriter->writeAttribute(
'val', ($element->getFont()->getItalic() ?
'true' :
'false'));
149 $objWriter->endElement();
152 if ($element->getFont()->getSuperscript() || $element->getFont()->getSubscript()) {
153 $objWriter->startElement($prefix .
'vertAlign');
154 if ($element->getFont()->getSuperscript()) {
155 $objWriter->writeAttribute(
'val',
'superscript');
156 } elseif ($element->getFont()->getSubscript()) {
157 $objWriter->writeAttribute(
'val',
'subscript');
159 $objWriter->endElement();
163 $objWriter->startElement($prefix .
'strike');
164 $objWriter->writeAttribute(
'val', ($element->getFont()->getStrikethrough() ?
'true' :
'false'));
165 $objWriter->endElement();
168 $objWriter->startElement($prefix .
'color');
169 $objWriter->writeAttribute(
'rgb', $element->getFont()->getColor()->getARGB());
170 $objWriter->endElement();
173 $objWriter->startElement($prefix .
'sz');
174 $objWriter->writeAttribute(
'val', $element->getFont()->getSize());
175 $objWriter->endElement();
178 $objWriter->startElement($prefix .
'u');
179 $objWriter->writeAttribute(
'val', $element->getFont()->getUnderline());
180 $objWriter->endElement();
182 $objWriter->endElement();
186 $objWriter->startElement($prefix .
't');
187 $objWriter->writeAttribute(
'xml:space',
'preserve');
189 $objWriter->endElement();
191 $objWriter->endElement();
204 if (!$pRichText instanceof
RichText) {
205 $textRun = $pRichText;
206 $pRichText =
new RichText();
207 $pRichText->createTextRun($textRun);
210 if ($prefix !== null) {
215 $elements = $pRichText->getRichTextElements();
216 foreach ($elements as $element) {
218 $objWriter->startElement($prefix .
'r');
221 $objWriter->startElement($prefix .
'rPr');
224 $objWriter->writeAttribute(
'b', ($element->getFont()->getBold() ? 1 : 0));
226 $objWriter->writeAttribute(
'i', ($element->getFont()->getItalic() ? 1 : 0));
228 $underlineType = $element->getFont()->getUnderline();
229 switch ($underlineType) {
231 $underlineType =
'sng';
235 $underlineType =
'dbl';
239 $objWriter->writeAttribute(
'u', $underlineType);
241 $objWriter->writeAttribute(
'strike', ($element->getFont()->getStrikethrough() ?
'sngStrike' :
'noStrike'));
244 $objWriter->startElement($prefix .
'latin');
245 $objWriter->writeAttribute(
'typeface', $element->getFont()->getName());
246 $objWriter->endElement();
248 $objWriter->endElement();
251 $objWriter->startElement($prefix .
't');
253 $objWriter->endElement();
255 $objWriter->endElement();
272 foreach ($stringTable as
$key => $value) {
274 $returnValue[$value] =
$key;
275 } elseif ($value instanceof RichText) {
276 $returnValue[$value->getHashCode()] =
$key;
static controlCharacterPHP2OOXML($value)
Convert from PHP control character to OpenXML escaped control character.
writeRawData($text)
Wrapper method for writeRaw.
writeRichText(XMLWriter $objWriter, RichText $pRichText, $prefix=null)
Write Rich Text.
getDiskCachingDirectory()
Get disk caching directory.
getCoordinates($sorted=true)
Get a sorted list of all cell coordinates currently held in the collection by row and column...
writeStringTable(array $pStringTable)
Write string table to XML format.
getParentWriter()
Get parent Xlsx object.
writeRichTextForCharts(XMLWriter $objWriter, $pRichText=null, $prefix=null)
Write Rich Text.
flipStringTable(array $stringTable)
Flip string table (for index searching).
getRichTextElements()
Get Rich Text elements.
createStringTable(Worksheet $pSheet, $pExistingTable=null)
Create worksheet stringtable.
getUseDiskCaching()
Get use disk caching where possible?