/** * Writes an excel cell * * @param string $cellValue * @param int $columnCount */ protected function writeCell($cellValue, $columnCount) { /** @var string $cellName */ $cellName = ExcelUtility::getXlSCell($this->rowCount, $columnCount); /** @var bool $isFormula */ $isFormula = FALSE; /** @var string $type */ if (!is_scalar($cellValue) || $cellValue === "") { $cellValue = ""; } elseif (is_string($cellValue) && $cellValue[0] == "=") { $type = "s"; $cellValue = ExcelUtility::xmlspecialchars($cellValue); $isFormula = TRUE; } elseif (!is_string($cellValue)) { $type = "n"; $cellValue = $cellValue * 1; } elseif ($cellValue[0] != "0" && $cellValue[0] != "+" && filter_var($cellValue, FILTER_VALIDATE_INT, array("options" => array("max_range" => 2147483647)))) { $type = "n"; $cellValue = $cellValue * 1; } else { $type = "s"; $cellValue = ExcelUtility::xmlspecialchars($this->doc->setSharedString($cellValue)); } $this->sheetData .= "<c r=\"" . $cellName . "\" s=\"" . $this->columns[$columnCount] . "\" "; if (isset($type) && !empty($type)) { $this->sheetData .= "t=\"" . $type . "\""; } $this->sheetData .= ">"; if (!$isFormula) { $this->sheetData .= "<v>" . $cellValue . "</v></c>"; } else { $this->sheetData .= "<f>" . $cellValue . "</f></c>"; } }
/** * Returns content of "/xl/workbook.xml" * * @return string */ protected function buildWorkbookXML() { /** @var string $xml */ $xml = ""; $xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; $xml .= "<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" "; $xml .= "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" "; $xml .= "xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x15\" "; $xml .= "xmlns:x15=\"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main\">"; $xml .= "<fileVersion appName=\"xl\" lastEdited=\"6\" lowestEdited=\"6\" rupBuild=\"14420\"/>"; $xml .= "<workbookPr defaultThemeVersion=\"153222\"/>"; $xml .= "<bookViews>"; $xml .= "<workbookView xWindow=\"0\" yWindow=\"0\" windowWidth=\"24270\" windowHeight=\"12570\"/>"; $xml .= "</bookViews>"; $xml .= "<sheets>"; /** @var int $i */ $i = 0; /** @var $sheet \BW\XlsxWriter\ExcelSheet */ foreach ($this->sheets as $sheet) { $xml .= "<sheet name=\"" . ExcelUtility::xmlspecialchars($sheet->getSheetName()) . "\" sheetId=\"" . ($i + 1) . "\" r:id=\"rId" . ($i + 2) . "\"/>"; $i++; } $xml .= "</sheets>"; $xml .= "<calcPr calcId=\"152511\"/>"; $xml .= "</workbook>"; return $xml; }