PHPExcel_Writer
[ class tree: PHPExcel_Writer ] [ index: PHPExcel_Writer ] [ all elements ]

Source for file HTML.php

Documentation is available at HTML.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2008 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Writer
  23.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.4, 2008-10-27
  26.  */
  27.  
  28.  
  29. /** PHPExcel_IWriter */
  30. require_once 'PHPExcel/Writer/IWriter.php';
  31.  
  32. /** PHPExcel_Cell */
  33. require_once 'PHPExcel/Cell.php';
  34.  
  35. /** PHPExcel_RichText */
  36. require_once 'PHPExcel/RichText.php';
  37.  
  38. /** PHPExcel_Shared_Drawing */
  39. require_once 'PHPExcel/Shared/Drawing.php';
  40.  
  41. /** PHPExcel_Shared_String */
  42. require_once 'PHPExcel/Shared/String.php';
  43.  
  44. /** PHPExcel_HashTable */
  45. require_once 'PHPExcel/HashTable.php';
  46.  
  47.  
  48. /**
  49.  * PHPExcel_Writer_HTML
  50.  *
  51.  * @category   PHPExcel
  52.  * @package    PHPExcel_Writer
  53.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  54.  */
  55. class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
  56.     /**
  57.      * PHPExcel object
  58.      *
  59.      * @var PHPExcel 
  60.      */
  61.     private $_phpExcel;
  62.  
  63.     /**
  64.      * Sheet index to write
  65.      *
  66.      * @var int 
  67.      */
  68.     private $_sheetIndex;
  69.  
  70.     /**
  71.      * Pre-calculate formulas
  72.      *
  73.      * @var boolean 
  74.      */
  75.     private $_preCalculateFormulas = true;
  76.  
  77.     /**
  78.      * Images root
  79.      *
  80.      * @var string 
  81.      */
  82.     private $_imagesRoot = '.';
  83.  
  84.     /**
  85.      * Create a new PHPExcel_Writer_HTML
  86.      *
  87.      * @param     PHPExcel    $phpExcel    PHPExcel object
  88.      */
  89.     public function __construct(PHPExcel $phpExcel{
  90.         $this->_phpExcel = $phpExcel;
  91.         $this->_sheetIndex = 0;
  92.         $this->_imagesRoot = '.';
  93.     }
  94.  
  95.     /**
  96.      * Save PHPExcel to file
  97.      *
  98.      * @param     string         $pFileName 
  99.      * @throws     Exception
  100.      */
  101.     public function save($pFilename null{
  102.         // Open file
  103.         $fileHandle fopen($pFilename'w');
  104.         if ($fileHandle === false{
  105.             throw new Exception("Could not open file $pFilename for writing.");
  106.         }
  107.  
  108.         // Write headers
  109.         fwrite($fileHandle$this->generateHTMLHeader());
  110.         fwrite($fileHandle$this->generateStyles(true));
  111.  
  112.         // Write data
  113.         fwrite($fileHandle$this->generateSheetData());
  114.  
  115.         // Write footer
  116.         fwrite($fileHandle$this->generateHTMLFooter());
  117.  
  118.         // Close file
  119.         fclose($fileHandle);
  120.     }
  121.  
  122.     /**
  123.      * Map VAlign
  124.      */
  125.     private function _mapVAlign($vAlign{
  126.         switch ($vAlign{
  127.             case PHPExcel_Style_Alignment::VERTICAL_BOTTOMreturn 'bottom';
  128.             case PHPExcel_Style_Alignment::VERTICAL_TOPreturn 'top';
  129.             case PHPExcel_Style_Alignment::VERTICAL_CENTER:
  130.             case PHPExcel_Style_Alignment::VERTICAL_JUSTIFYreturn 'middle';
  131.             defaultreturn ' baseline';
  132.         }
  133.     }
  134.  
  135.     /**
  136.      * Map HAlign
  137.      */
  138.     private function _mapHAlign($hAlign{
  139.         switch ($hAlign{
  140.             case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
  141.             case PHPExcel_Style_Alignment::HORIZONTAL_LEFTreturn 'left';
  142.             case PHPExcel_Style_Alignment::HORIZONTAL_RIGHTreturn 'right';
  143.             case PHPExcel_Style_Alignment::HORIZONTAL_CENTERreturn 'center';
  144.             case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFYreturn 'justify';
  145.             defaultreturn ' baseline';
  146.         }
  147.     }
  148.  
  149.     /**
  150.      * Map border style
  151.      */
  152.     private function _mapBorderStyle($borderStyle{
  153.         switch ($borderStyle{
  154.             case PHPExcel_Style_Border::BORDER_NONEreturn '0px';
  155.             case PHPExcel_Style_Border::BORDER_DASHEDreturn '1px dashed';
  156.             case PHPExcel_Style_Border::BORDER_DOTTEDreturn '1px dotted';
  157.             case PHPExcel_Style_Border::BORDER_THICKreturn '2px solid';
  158.             defaultreturn '1px solid'// map others to thin
  159.         }
  160.     }
  161.  
  162.     /**
  163.      * Get sheet index
  164.      *
  165.      * @return int 
  166.      */
  167.     public function getSheetIndex({
  168.         return $this->_sheetIndex;
  169.     }
  170.  
  171.     /**
  172.      * Set sheet index
  173.      *
  174.      * @param    int        $pValue        Sheet index
  175.      */
  176.     public function setSheetIndex($pValue 0{
  177.         $this->_sheetIndex = $pValue;
  178.     }
  179.  
  180.     /**
  181.      * Write all sheets (resets sheetIndex to NULL)
  182.      */
  183.     public function writeAllSheets({
  184.         $this->_sheetIndex = null;
  185.     }
  186.  
  187.     /**
  188.      * Generate HTML header
  189.      *
  190.      * @return    string 
  191.      * @throws Exception
  192.      */
  193.     public function generateHTMLHeader({
  194.         // PHPExcel object known?
  195.         if (is_null($this->_phpExcel)) {
  196.             throw new Exception('Internal PHPExcel object not set to an instance of an object.');
  197.         }
  198.  
  199.         // Construct HTML
  200.         $html '';
  201.         $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' "\r\n";
  202.         $html .= '<html>' "\r\n";
  203.         $html .= '  <head>' "\r\n";
  204.         $html .= '    <title>' $this->_phpExcel->getProperties()->getTitle('</title>' "\r\n";
  205.         $html .= '  </head>' "\r\n";
  206.         $html .= '' "\r\n";
  207.         $html .= '  <body>' "\r\n";
  208.  
  209.         // Return
  210.         return $html;
  211.     }
  212.  
  213.     /**
  214.      * Generate sheet data
  215.      *
  216.      * @return    string 
  217.      * @throws Exception
  218.      */
  219.     public function generateSheetData({
  220.         // PHPExcel object known?
  221.         if (is_null($this->_phpExcel)) {
  222.             throw new Exception('Internal PHPExcel object not set to an instance of an object.');
  223.         }
  224.  
  225.         // Fetch sheets
  226.         $sheets array();
  227.         if (is_null($this->_sheetIndex)) {
  228.             $sheets $this->_phpExcel->getAllSheets();
  229.         else {
  230.             $sheets[$this->_phpExcel->getSheet($this->_sheetIndex);
  231.         }
  232.  
  233.         // Construct HTML
  234.         $html '';
  235.  
  236.         // Loop all sheets
  237.         foreach ($sheets as $sheet{
  238.             // Calculate hash code
  239.             $hashCode $sheet->getHashCode();
  240.  
  241.             // Get cell collection
  242.             $cellCollection $sheet->getCellCollection();
  243.  
  244.             // Write table header
  245.             $html .= $this->_generateTableHeader($hashCode);
  246.  
  247.             // Get worksheet dimension
  248.             $dimension explode(':'$sheet->calculateWorksheetDimension());
  249.             $dimension[0PHPExcel_Cell::coordinateFromString($dimension[0]);
  250.             $dimension[0][0PHPExcel_Cell::columnIndexFromString($dimension[0][0]1;
  251.             $dimension[1PHPExcel_Cell::coordinateFromString($dimension[1]);
  252.             $dimension[1][0PHPExcel_Cell::columnIndexFromString($dimension[1][0]1;
  253.  
  254.             // Loop trough cells
  255.             $rowData null;
  256.             for ($row $dimension[0][1]$row <= $dimension[1][1]++$row{
  257.                 // Start a new row
  258.                 $rowData array();
  259.  
  260.                 // Loop trough columns
  261.                 for ($column $dimension[0][0]$column <= $dimension[1][0]++$column{
  262.                     // Cell exists?
  263.                     if ($sheet->cellExistsByColumnAndRow($column$row)) {
  264.                         $rowData[$column$sheet->getCellByColumnAndRow($column$row);
  265.                     else {
  266.                         $rowData[$column'';
  267.                     }
  268.                 }
  269.  
  270.                 // Write row
  271.                 $html .= $this->_generateRow($sheet$rowData$row 1);
  272.             }
  273.  
  274.             // Write table footer
  275.             $html .= $this->_generateTableFooter();
  276.         }
  277.  
  278.         // Return
  279.         return $html;
  280.     }
  281.  
  282.     /**
  283.      * Generate image tag in cell
  284.      *
  285.      * @param    PHPExcel_Worksheet     $pSheet            PHPExcel_Worksheet
  286.      * @param    string                $coordinates    Cell coordinates
  287.      * @retrun    string
  288.      * @throws    Exception
  289.      */
  290.     private function _writeImageTagInCell(PHPExcel_Worksheet $pSheet$coordinates{
  291.         // Construct HTML
  292.         $html '';
  293.  
  294.         // Write images
  295.         foreach ($pSheet->getDrawingCollection(as $drawing{
  296.             if ($drawing instanceof PHPExcel_Worksheet_BaseDrawing{
  297.                 if ($drawing->getCoordinates(== $coordinates{
  298.                     $filename $drawing->getPath();
  299.  
  300.                     // Strip off eventual '.'
  301.                     if (substr($filename01== '.'{
  302.                         $filename substr($filename1);
  303.                     }
  304.  
  305.                     // Prepend images root
  306.                     $filename $this->getImagesRoot($filename;
  307.  
  308.                     // Strip off eventual '.'
  309.                     if (substr($filename01== '.' && substr($filename02!= './'{
  310.                         $filename substr($filename1);
  311.                     }
  312.  
  313.                     $html .= "\r\n";
  314.                     $html .= '        <img  style="position: relative; left: ' $drawing->getOffsetX('px; top: ' $drawing->getOffsetY('px; width: ' $drawing->getWidth('px; height: ' $drawing->getHeight('px;" src="' $filename '" border="0">' "\r\n";
  315.                 }
  316.             }
  317.         }
  318.  
  319.         // Return
  320.         return $html;
  321.     }
  322.  
  323.     /**
  324.      * Generate CSS styles
  325.      *
  326.      * @param    boolean    $generateSurroundingHTML    Generate surrounding HTML tags? (<style> and </style>)
  327.      * @return    string 
  328.      * @throws    Exception
  329.      */
  330.     public function generateStyles($generateSurroundingHTML true{
  331.         // PHPExcel object known?
  332.         if (is_null($this->_phpExcel)) {
  333.             throw new Exception('Internal PHPExcel object not set to an instance of an object.');
  334.         }
  335.  
  336.         // Construct HTML
  337.         $html '';
  338.  
  339.         // Start styles
  340.         if ($generateSurroundingHTML{
  341.             $html .= '    <style>' "\r\n";
  342.             $html .= '    <!--' "\r\n";
  343.             $html .= '      html {' "\r\n";
  344.             $html .= '        font-family: Calibri, Arial, Helvetica, Sans Serif;' "\r\n";
  345.             $html .= '        font-size: 10pt;' "\r\n";
  346.             $html .= '        background-color: white;' "\r\n";
  347.             $html .= '      }' "\r\n";
  348.         }
  349.  
  350.         // Write styles per sheet
  351.         foreach ($this->_phpExcel->getAllSheets(as $sheet{
  352.             // Calculate hash code
  353.             $hashCode $sheet->getHashCode();
  354.  
  355.             // Write styles
  356.             $html .= '      table.sheet' $hashCode ', table.sheet' $hashCode ' td {' "\r\n";
  357.             if ($sheet->getShowGridlines()) {
  358.                 $html .= '        border: 1px dotted black;' "\r\n";
  359.             }
  360.             $html .= '        page-break-after: always;' "\r\n";
  361.             $html .= '      }' "\r\n";
  362.  
  363.             // Default column width
  364.             $columnDimension $sheet->getDefaultColumnDimension();
  365.  
  366.             $html .= '      table.sheet' $hashCode ' td {' "\r\n";
  367.             $html .= '        width: ' PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth()) 'px;' "\r\n";
  368.             if ($columnDimension->getVisible(=== false{
  369.                 $html .= '        display: none;' "\r\n";
  370.                 $html .= '        visibility: hidden;' "\r\n";
  371.             }
  372.             $html .= '      }' "\r\n";
  373.  
  374.             // Calculate column widths
  375.             $sheet->calculateColumnWidths();
  376.             foreach ($sheet->getColumnDimensions(as $columnDimension{
  377.                 $column PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) 1;
  378.  
  379.                 $html .= '      table.sheet' $hashCode ' td.column' $column  ' {' "\r\n";
  380.                 $html .= '        width: ' PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth()) 'px;' "\r\n";
  381.                 if ($columnDimension->getVisible(=== false{
  382.                     $html .= '        display: none;' "\r\n";
  383.                     $html .= '        visibility: hidden;' "\r\n";
  384.                 }
  385.                 $html .= '      }' "\r\n";
  386.             }
  387.  
  388.             // Default row height
  389.             $rowDimension $sheet->getDefaultRowDimension();
  390.  
  391.             $html .= '      table.sheet' $hashCode ' tr {' "\r\n";
  392.             // height is disproportionately large
  393.             $px_height roundPHPExcel_Shared_Drawing::cellDimensionToPixels($rowDimension->getRowHeight()) 12 );
  394.             $html .= '        height: ' $px_height 'px;' "\r\n";
  395.             if ($rowDimension->getVisible(=== false{
  396.                 $html .= '        display: none;' "\r\n";
  397.                 $html .= '        visibility: hidden;' "\r\n";
  398.             }
  399.             $html .= '      }' "\r\n";
  400.  
  401.             // Calculate row heights
  402.             foreach ($sheet->getRowDimensions(as $rowDimension{
  403.                 $html .= '      table.sheet' $hashCode ' tr.row' ($rowDimension->getRowIndex(1)  ' {' "\r\n";
  404.                 // height is disproportionately large
  405.                 $px_height roundPHPExcel_Shared_Drawing::cellDimensionToPixels($rowDimension->getRowHeight()) 12 );
  406.                 $html .= '        height: ' $px_height 'px;' "\r\n";
  407.                 if ($rowDimension->getVisible(=== false{
  408.                     $html .= '        display: none;' "\r\n";
  409.                     $html .= '        visibility: hidden;' "\r\n";
  410.                 }
  411.                 $html .= '      }' "\r\n";
  412.             }
  413.  
  414.             // Calculate cell style hashes
  415.             $cellStyleHashes new PHPExcel_HashTable();
  416.             $cellStyleHashes->addFromSource$sheet->getStyles() );
  417.             for ($i 0$i $cellStyleHashes->count()++$i{
  418.                 $html .= $this->_createCSSStyle$cellStyleHashes->getByIndex($i) );
  419.             }
  420.         }
  421.  
  422.         // End styles
  423.         if ($generateSurroundingHTML{
  424.             $html .= '    -->' "\r\n";
  425.             $html .= '    </style>' "\r\n";
  426.         }
  427.  
  428.         // Return
  429.         return $html;
  430.     }
  431.  
  432.     /**
  433.      * Create CSS style
  434.      *
  435.      * @param    PHPExcel_Style         $pStyle            PHPExcel_Style
  436.      * @return    string 
  437.      */
  438.     private function _createCSSStyle(PHPExcel_Style $pStyle{
  439.         // Construct HTML
  440.         $html '';
  441.  
  442.         // Create CSS
  443.         $html .= '      .style' $pStyle->getHashCode(' {' "\r\n";
  444.         $html .= $this->_createCSSStyleAlignment($pStyle->getAlignment());
  445.         $html .= $this->_createCSSStyleFont($pStyle->getFont());
  446.         $html .= $this->_createCSSStyleBorders($pStyle->getBorders());
  447.         $html .= $this->_createCSSStyleFill($pStyle->getFill());
  448.         $html .= '      }' "\r\n";
  449.  
  450.         // Return
  451.         return $html;
  452.     }
  453.  
  454.     /**
  455.      * Create CSS style (PHPExcel_Style_Alignment)
  456.      *
  457.      * @param    PHPExcel_Style_Alignment         $pStyle            PHPExcel_Style_Alignment
  458.      * @return    string 
  459.      */
  460.     private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle{
  461.         // Construct HTML
  462.         $html '';
  463.  
  464.         // Create CSS
  465.         $html .= '        vertical-align: '     $this->_mapVAlign($pStyle->getVertical()) ';' "\r\n";
  466.         $html .= '        text-align: '         $this->_mapHAlign($pStyle->getHorizontal()) ';' "\r\n";
  467.  
  468.         // Return
  469.         return $html;
  470.     }
  471.  
  472.     /**
  473.      * Create CSS style (PHPExcel_Style_Font)
  474.      *
  475.      * @param    PHPExcel_Style_Font         $pStyle            PHPExcel_Style_Font
  476.      * @return    string 
  477.      */
  478.     private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle{
  479.         // Construct HTML
  480.         $html '';
  481.  
  482.         // Create CSS
  483.         if ($pStyle->getBold()) {
  484.             $html .= '        font-weight: bold;' "\r\n";
  485.         }
  486.         if ($pStyle->getUnderline(!= PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStriketrough()) {
  487.             $html .= '        text-decoration: underline line-through;' "\r\n";
  488.         else if ($pStyle->getUnderline(!= PHPExcel_Style_Font::UNDERLINE_NONE{
  489.             $html .= '        text-decoration: underline;' "\r\n";
  490.         else if ($pStyle->getStriketrough()) {
  491.             $html .= '        text-decoration: line-through;' "\r\n";
  492.         }
  493.         if ($pStyle->getItalic()) {
  494.             $html .= '        font-style: italic;' "\r\n";
  495.         }
  496.  
  497.         $html .= '        color: '                 '#' $pStyle->getColor()->getRGB(';' "\r\n";
  498.         $html .= '        font-family: '         $pStyle->getName(';' "\r\n";
  499.         $html .= '        font-size: '             $pStyle->getSize('pt;' "\r\n";
  500.  
  501.         // Return
  502.         return $html;
  503.     }
  504.  
  505.     /**
  506.      * Create CSS style (PHPExcel_Style_Borders)
  507.      *
  508.      * @param    PHPExcel_Style_Borders         $pStyle            PHPExcel_Style_Borders
  509.      * @return    string 
  510.      */
  511.     private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle{
  512.         // Construct HTML
  513.         $html '';
  514.  
  515.         // Create CSS
  516.         $html .= '        border-bottom: '         $this->_createCSSStyleBorder($pStyle->getBottom()) ';' "\r\n";
  517.         $html .= '        border-top: '         $this->_createCSSStyleBorder($pStyle->getTop()) ';' "\r\n";
  518.         $html .= '        border-left: '         $this->_createCSSStyleBorder($pStyle->getLeft()) ';' "\r\n";
  519.         $html .= '        border-right: '         $this->_createCSSStyleBorder($pStyle->getRight()) ';' "\r\n";
  520.  
  521.         // Return
  522.         return $html;
  523.     }
  524.  
  525.     /**
  526.      * Create CSS style (PHPExcel_Style_Border)
  527.      *
  528.      * @param    PHPExcel_Style_Border        $pStyle            PHPExcel_Style_Border
  529.      * @return    string 
  530.      */
  531.     private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle{
  532.         // Construct HTML
  533.         $html '';
  534.  
  535.         // Create CSS
  536.         $html .= $this->_mapBorderStyle($pStyle->getBorderStyle()) ' #' $pStyle->getColor()->getRGB();
  537.  
  538.         // Return
  539.         return $html;
  540.     }
  541.  
  542.     /**
  543.      * Create CSS style (PHPExcel_Style_Fill)
  544.      *
  545.      * @param    PHPExcel_Style_Fill        $pStyle            PHPExcel_Style_Fill
  546.      * @return    string 
  547.      */
  548.     private function _createCSSStyleFill(PHPExcel_Style_Fill $pStyle{
  549.         // Construct HTML
  550.         $html '';
  551.  
  552.         // Create CSS
  553.         $html .= '        background-color: '     '#' $pStyle->getStartColor()->getRGB(';' "\r\n";
  554.  
  555.         // Return
  556.         return $html;
  557.     }
  558.  
  559.     /**
  560.      * Generate HTML footer
  561.      */
  562.     public function generateHTMLFooter({
  563.         // Construct HTML
  564.         $html '';
  565.         $html .= '  </body>' "\r\n";
  566.         $html .= '</html>' "\r\n";
  567.  
  568.         // Return
  569.         return $html;
  570.     }
  571.  
  572.     /**
  573.      * Generate table header
  574.      *
  575.      * @param     string    $pIdentifier    Identifier for the table
  576.      * @return    string 
  577.      * @throws    Exception
  578.      */
  579.     private function _generateTableHeader($pIdentifier ''{
  580.         // Construct HTML
  581.         $html '';
  582.         $html .= '    <table border="0" cellpadding="0" cellspacing="0" class="sheet' $pIdentifier '">' "\r\n";
  583.  
  584.         // Return
  585.         return $html;
  586.     }
  587.  
  588.     /**
  589.      * Generate table footer
  590.      *
  591.      * @throws    Exception
  592.      */
  593.     private function _generateTableFooter({
  594.         // Construct HTML
  595.         $html '';
  596.         $html .= '    </table>' "\r\n";
  597.  
  598.         // Return
  599.         return $html;
  600.     }
  601.  
  602.     /**
  603.      * Generate row
  604.      *
  605.      * @param    PHPExcel_Worksheet     $pSheet            PHPExcel_Worksheet
  606.      * @param    array                $pValues        Array containing cells in a row
  607.      * @param    int                    $pRow            Row number
  608.      * @return    string 
  609.      * @throws    Exception
  610.      */
  611.     private function _generateRow(PHPExcel_Worksheet $pSheet$pValues null$pRow 0{
  612.         if (is_array($pValues)) {
  613.             // Construct HTML
  614.             $html '';
  615.  
  616.             // Write row start
  617.             $html .= '        <tr class="row' $pRow '">' "\r\n";
  618.  
  619.             // Write cells
  620.             $colNum 0;
  621.             foreach ($pValues as $cell{
  622.                 $cellData '&nbsp;';
  623.                 $cssClass 'column' $colNum;
  624.                 $colSpan 1;
  625.                 $rowSpan 1;
  626.                 $writeCell true;    // Write cell
  627.  
  628.                 // PHPExcel_Cell
  629.                 if ($cell instanceof PHPExcel_Cell{
  630.                     // Value
  631.                     if ($cell->getValue(instanceof PHPExcel_RichText{
  632.                         // Loop trough rich text elements
  633.                         $elements $cell->getValue()->getRichTextElements();
  634.                         foreach ($elements as $element{
  635.                             // Rich text start?
  636.                             if ($element instanceof PHPExcel_RichText_Run{
  637.                                 $cellData .= '<span style="' .
  638.                                     str_replace("\r\n"'',
  639.                                         $this->_createCSSStyleFont($element->getFont())
  640.                                     '">';
  641.  
  642.                                 if ($element->getFont()->getSuperScript()) {
  643.                                     $cellData .= '<sup>';
  644.                                 else if ($element->getFont()->getSubScript()) {
  645.                                     $cellData .= '<sub>';
  646.                                 }
  647.                             }
  648.  
  649.                             // Decode UTF8 data
  650.                             $cellText $element->getText();
  651.                             if (PHPExcel_Shared_String::IsUTF8($cellText)) {
  652.                                 $cellData .= utf8_decode($cellText);
  653.                             }
  654.  
  655.                             if ($element instanceof PHPExcel_RichText_Run{
  656.                                 if ($element->getFont()->getSuperScript()) {
  657.                                     $cellData .= '</sup>';
  658.                                 else if ($element->getFont()->getSubScript()) {
  659.                                     $cellData .= '</sub>';
  660.                                 }
  661.  
  662.                                 $cellData .= '</span>';
  663.                             }
  664.                         }
  665.                     else {
  666.                         if ($this->_preCalculateFormulas{
  667.                             $cellData PHPExcel_Style_NumberFormat::toFormattedString(
  668.                                 $cell->getCalculatedValue(),
  669.                                 $pSheet->getstyle$cell->getCoordinate() )->getNumberFormat()->getFormatCode()
  670.                             );
  671.                         else {
  672.                             $cellData PHPExcel_Style_NumberFormat::ToFormattedString(
  673.                                 $cell->getValue(),
  674.                                 $pSheet->getstyle$cell->getCoordinate() )->getNumberFormat()->getFormatCode()
  675.                             );
  676.                         }
  677.  
  678.                         // Decode UTF8 data
  679.                         if (PHPExcel_Shared_String::IsUTF8($cellData)) {
  680.                             $cellData utf8_decode($cellData);
  681.                         }
  682.                     }
  683.  
  684.                     // Check value
  685.                     if ($cellData == ''{
  686.                         $cellData '&nbsp;';
  687.                     }
  688.  
  689.                     // Extend CSS class?
  690.                     if (array_key_exists($cell->getCoordinate()$pSheet->getStyles())) {
  691.                         $cssClass .= ' style' $pSheet->getStyle($cell->getCoordinate())->getHashCode();
  692.                     }
  693.                 else {
  694.                     $cell new PHPExcel_Cell(
  695.                         PHPExcel_Cell::stringFromColumnIndex($colNum),
  696.                         ($pRow 1),
  697.                         '',
  698.                         null,
  699.                         null
  700.                     );
  701.                 }
  702.  
  703.                 // Hyperlink?
  704.                 if ($cell->hasHyperlink(&& !$cell->getHyperlink()->isInternal()) {
  705.                     $cellData '<a href="' $cell->getHyperlink()->getUrl('" title="' $cell->getHyperlink()->getTooltip('">' $cellData '</a>';
  706.                 }
  707.  
  708.                 // Column/rowspan
  709.                 foreach ($pSheet->getMergeCells(as $cells{
  710.                     if ($cell->isInRange($cells)) {
  711.                         list($firstPHPExcel_Cell::splitRange($cells);
  712.  
  713.                         if ($first == $cell->getCoordinate()) {
  714.                             list($colSpan$rowSpanPHPExcel_Cell::rangeDimension($cells);
  715.                         else {
  716.                             $writeCell false;
  717.                         }
  718.  
  719.                         break;
  720.                     }
  721.                 }
  722.  
  723.                 // Write
  724.                 if ($writeCell{
  725.                     // Column start
  726.                     $html .= '          <td';
  727.                         $html .= ' class="' $cssClass '"';
  728.                         if ($colSpan 1{
  729.                             $html .= ' colspan="' $colSpan '"';
  730.                         }
  731.                         if ($rowSpan 1{
  732.                             $html .= ' rowspan="' $rowSpan '"';
  733.                         }
  734.                     $html .= '>';
  735.  
  736.                     // Image?
  737.                     $html .= $this->_writeImageTagInCell($pSheet$cell->getCoordinate());
  738.  
  739.                     // Cell data
  740.                     $html .= $cellData;
  741.  
  742.                     // Column end
  743.                     $html .= '</td>' "\r\n";
  744.                 }
  745.  
  746.                 // Next column
  747.                 ++$colNum;
  748.             }
  749.  
  750.             // Write row end
  751.             $html .= '        </tr>' "\r\n";
  752.  
  753.             // Return
  754.             return $html;
  755.         else {
  756.             throw new Exception("Invalid parameters passed.");
  757.         }
  758.     }
  759.  
  760.  
  761.     /**
  762.      * Get Pre-Calculate Formulas
  763.      *
  764.      * @return boolean 
  765.      */
  766.     public function getPreCalculateFormulas({
  767.         return $this->_preCalculateFormulas;
  768.     }
  769.  
  770.     /**
  771.      * Set Pre-Calculate Formulas
  772.      *
  773.      * @param boolean $pValue    Pre-Calculate Formulas?
  774.      */
  775.     public function setPreCalculateFormulas($pValue true{
  776.         $this->_preCalculateFormulas = $pValue;
  777.     }
  778.  
  779.     /**
  780.      * Get images root
  781.      *
  782.      * @return string 
  783.      */
  784.     public function getImagesRoot({
  785.         return $this->_imagesRoot;
  786.     }
  787.  
  788.     /**
  789.      * Set images root
  790.      *
  791.      * @param string $pValue 
  792.      */
  793.     public function setImagesRoot($pValue '.'{
  794.         $this->_imagesRoot = $pValue;
  795.     }
  796. }

Documentation generated on Mon, 27 Oct 2008 08:40:06 +0100 by phpDocumentor 1.4.1