public function getContentXmlAutomaticStylesSectionContent($numWorksheets) { $content = '<office:automatic-styles>'; foreach ($this->getRegisteredStyles() as $style) { $content .= $this->getStyleSectionContent($style); } $content .= <<<EOD <style:style style:family="table-column" style:name="co1"> <style:table-column-properties fo:break-before="auto"/> </style:style> <style:style style:family="table-row" style:name="ro1"> <style:table-row-properties fo:break-before="auto" style:row-height="15pt" style:use-optimal-row-height="true"/> </style:style> EOD; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= <<<EOD <style:style style:family="table" style:master-page-name="mp{$i}" style:name="ta{$i}"> <style:table-properties style:writing-mode="lr-tb" table:display="true"/> </style:style> EOD; } $content .= '</office:automatic-styles>'; return $content; }
/** * Creates the "content.xml" file under the root folder * * @param Worksheet[] $worksheets * @param StyleHelper $styleHelper * @return FileSystemHelper */ public function createContentFile($worksheets, $styleHelper) { $contentXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> EOD; $contentXmlFileContents .= $styleHelper->getContentXmlFontFaceSectionContent(); $contentXmlFileContents .= $styleHelper->getContentXmlAutomaticStylesSectionContent(count($worksheets)); $contentXmlFileContents .= '<office:body><office:spreadsheet>'; $this->createFileWithContents($this->rootFolder, self::CONTENT_XML_FILE_NAME, $contentXmlFileContents); // Append sheets content to "content.xml" $contentXmlFilePath = $this->rootFolder . '/' . self::CONTENT_XML_FILE_NAME; $contentXmlHandle = fopen($contentXmlFilePath, 'a'); foreach ($worksheets as $worksheet) { // write the "<table:table>" node, with the final sheet's name fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString()); $worksheetFilePath = $worksheet->getWorksheetFilePath(); $this->copyFileContentsToTarget($worksheetFilePath, $contentXmlHandle); fwrite($contentXmlHandle, '</table:table>'); } $contentXmlFileContents = '</office:spreadsheet></office:body></office:document-content>'; fwrite($contentXmlHandle, $contentXmlFileContents); fclose($contentXmlHandle); return $this; }