コード例 #1
0
ファイル: HTML.php プロジェクト: kameshwariv/testexample
 /**
  * Generate HTML header
  *
  * @param    boolean        $pIncludeStyles        Include styles?
  * @return    string
  * @throws \PHPExcel\Writer\Exception
  */
 public function generateHTMLHeader($pIncludeStyles = false)
 {
     // PHPExcel object known?
     if (is_null($this->phpExcel)) {
         throw new \PHPExcel\Writer\Exception('Internal PHPExcel object not set to an instance of an object.');
     }
     // Construct HTML
     $properties = $this->phpExcel->getProperties();
     $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL;
     $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL;
     $html .= '<html>' . PHP_EOL;
     $html .= '  <head>' . PHP_EOL;
     $html .= '      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL;
     if ($properties->getTitle() > '') {
         $html .= '      <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL;
     }
     if ($properties->getCreator() > '') {
         $html .= '      <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL;
     }
     if ($properties->getTitle() > '') {
         $html .= '      <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL;
     }
     if ($properties->getDescription() > '') {
         $html .= '      <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL;
     }
     if ($properties->getSubject() > '') {
         $html .= '      <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL;
     }
     if ($properties->getKeywords() > '') {
         $html .= '      <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL;
     }
     if ($properties->getCategory() > '') {
         $html .= '      <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL;
     }
     if ($properties->getCompany() > '') {
         $html .= '      <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL;
     }
     if ($properties->getManager() > '') {
         $html .= '      <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL;
     }
     if ($pIncludeStyles) {
         $html .= $this->generateStyles(true);
     }
     $html .= '  </head>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '  <body>' . PHP_EOL;
     return $html;
 }
コード例 #2
0
 /**
  * Write content types to XML format
  *
  * @param     \PHPExcel\Spreadsheet    $pPHPExcel
  * @param    boolean        $includeCharts    Flag indicating if we should include drawing details for charts
  * @return string                  XML Output
  * @throws     \PHPExcel\Writer\Exception
  */
 public function writeContentTypes(\PHPExcel\Spreadsheet $pPHPExcel = null, $includeCharts = false)
 {
     // Create XML writer
     $objWriter = null;
     if ($this->getParentWriter()->getUseDiskCaching()) {
         $objWriter = new \PHPExcel\Shared\XMLWriter(\PHPExcel\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
     } else {
         $objWriter = new \PHPExcel\Shared\XMLWriter(\PHPExcel\Shared\XMLWriter::STORAGE_MEMORY);
     }
     // XML header
     $objWriter->startDocument('1.0', 'UTF-8', 'yes');
     // Types
     $objWriter->startElement('Types');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
     // Theme
     $this->writeOverrideContentType($objWriter, '/xl/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml');
     // Styles
     $this->writeOverrideContentType($objWriter, '/xl/styles.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml');
     // Rels
     $this->writeDefaultContentType($objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml');
     // XML
     $this->writeDefaultContentType($objWriter, 'xml', 'application/xml');
     // VML
     $this->writeDefaultContentType($objWriter, 'vml', 'application/vnd.openxmlformats-officedocument.vmlDrawing');
     // Workbook
     if ($pPHPExcel->hasMacros()) {
         //Macros in workbook ?
         // Yes : not standard content but "macroEnabled"
         $this->writeOverrideContentType($objWriter, '/xl/workbook.xml', 'application/vnd.ms-excel.sheet.macroEnabled.main+xml');
         //... and define a new type for the VBA project
         $this->writeDefaultContentType($objWriter, 'bin', 'application/vnd.ms-office.vbaProject');
         if ($pPHPExcel->hasMacrosCertificate()) {
             // signed macros ?
             // Yes : add needed information
             $this->writeOverrideContentType($objWriter, '/xl/vbaProjectSignature.bin', 'application/vnd.ms-office.vbaProjectSignature');
         }
     } else {
         // no macros in workbook, so standard type
         $this->writeOverrideContentType($objWriter, '/xl/workbook.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml');
     }
     // DocProps
     $this->writeOverrideContentType($objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml');
     $this->writeOverrideContentType($objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml');
     $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
     if (!empty($customPropertyList)) {
         $this->writeOverrideContentType($objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml');
     }
     // Worksheets
     $sheetCount = $pPHPExcel->getSheetCount();
     for ($i = 0; $i < $sheetCount; ++$i) {
         $this->writeOverrideContentType($objWriter, '/xl/worksheets/sheet' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml');
     }
     // Shared strings
     $this->writeOverrideContentType($objWriter, '/xl/sharedStrings.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml');
     // Add worksheet relationship content types
     $chart = 1;
     for ($i = 0; $i < $sheetCount; ++$i) {
         $drawings = $pPHPExcel->getSheet($i)->getDrawingCollection();
         $drawingCount = count($drawings);
         $chartCount = $includeCharts ? $pPHPExcel->getSheet($i)->getChartCount() : 0;
         //    We need a drawing relationship for the worksheet if we have either drawings or charts
         if ($drawingCount > 0 || $chartCount > 0) {
             $this->writeOverrideContentType($objWriter, '/xl/drawings/drawing' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.drawing+xml');
         }
         //    If we have charts, then we need a chart relationship for every individual chart
         if ($chartCount > 0) {
             for ($c = 0; $c < $chartCount; ++$c) {
                 $this->writeOverrideContentType($objWriter, '/xl/charts/chart' . $chart++ . '.xml', 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
             }
         }
     }
     // Comments
     for ($i = 0; $i < $sheetCount; ++$i) {
         if (count($pPHPExcel->getSheet($i)->getComments()) > 0) {
             $this->writeOverrideContentType($objWriter, '/xl/comments' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml');
         }
     }
     // Add media content-types
     $aMediaContentTypes = array();
     $mediaCount = $this->getParentWriter()->getDrawingHashTable()->count();
     for ($i = 0; $i < $mediaCount; ++$i) {
         $extension = '';
         $mimeType = '';
         if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof \PHPExcel\Worksheet\Drawing) {
             $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
             $mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
         } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof \PHPExcel\Worksheet\MemoryDrawing) {
             $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
             $extension = explode('/', $extension);
             $extension = $extension[1];
             $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
         }
         if (!isset($aMediaContentTypes[$extension])) {
             $aMediaContentTypes[$extension] = $mimeType;
             $this->writeDefaultContentType($objWriter, $extension, $mimeType);
         }
     }
     if ($pPHPExcel->hasRibbonBinObjects()) {
         // Some additional objects in the ribbon ?
         // we need to write "Extension" but not already write for media content
         $tabRibbonTypes = array_diff($pPHPExcel->getRibbonBinObjects('types'), array_keys($aMediaContentTypes));
         foreach ($tabRibbonTypes as $aRibbonType) {
             $mimeType = 'image/.' . $aRibbonType;
             //we wrote $mimeType like customUI Editor
             $this->writeDefaultContentType($objWriter, $aRibbonType, $mimeType);
         }
     }
     $sheetCount = $pPHPExcel->getSheetCount();
     for ($i = 0; $i < $sheetCount; ++$i) {
         if (count($pPHPExcel->getSheet()->getHeaderFooter()->getImages()) > 0) {
             foreach ($pPHPExcel->getSheet()->getHeaderFooter()->getImages() as $image) {
                 if (!isset($aMediaContentTypes[strtolower($image->getExtension())])) {
                     $aMediaContentTypes[strtolower($image->getExtension())] = $this->getImageMimeType($image->getPath());
                     $this->writeDefaultContentType($objWriter, strtolower($image->getExtension()), $aMediaContentTypes[strtolower($image->getExtension())]);
                 }
             }
         }
     }
     $objWriter->endElement();
     // Return
     return $objWriter->getData();
 }