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

Source for file Comments.php

Documentation is available at Comments.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 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_Excel2007
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** PHPExcel */
  30. require_once 'PHPExcel.php';
  31.  
  32. /** PHPExcel_Writer_Excel2007 */
  33. require_once 'PHPExcel/Writer/Excel2007.php';
  34.  
  35. /** PHPExcel_Writer_Excel2007_WriterPart */
  36. require_once 'PHPExcel/Writer/Excel2007/WriterPart.php';
  37.  
  38. /** PHPExcel_Worksheet */
  39. require_once 'PHPExcel/Worksheet.php';
  40.  
  41. /** PHPExcel_Comment */
  42. require_once 'PHPExcel/Comment.php';
  43.  
  44. /** PHPExcel_RichText */
  45. require_once 'PHPExcel/RichText.php';
  46.  
  47. /** PHPExcel_Cell */
  48. require_once 'PHPExcel/Cell.php';
  49.  
  50. /** PHPExcel_Style_Color */
  51. require_once 'PHPExcel/Style/Color.php';
  52.  
  53. /** PHPExcel_Shared_XMLWriter */
  54. require_once 'PHPExcel/Shared/XMLWriter.php';
  55.  
  56.  
  57. /**
  58.  * PHPExcel_Writer_Excel2007_Comments
  59.  *
  60.  * @category   PHPExcel
  61.  * @package    PHPExcel_Writer_Excel2007
  62.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  63.  */
  64. {
  65.     /**
  66.      * Write comments to XML format
  67.      *
  68.      * @param     PHPExcel_Worksheet                $pWorksheet 
  69.      * @return     string                                 XML Output
  70.      * @throws     Exception
  71.      */
  72.     public function writeComments(PHPExcel_Worksheet $pWorksheet null)
  73.     {
  74.         // Create XML writer
  75.         $objWriter null;
  76.         if ($this->getParentWriter()->getUseDiskCaching()) {
  77.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK);
  78.         else {
  79.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  80.         }
  81.             
  82.         // XML header
  83.         $objWriter->startDocument('1.0','UTF-8','yes');
  84.   
  85.           // Comments cache
  86.           $comments    $pWorksheet->getComments();
  87.           
  88.           // Authors cache
  89.           $authors    array();
  90.           $authorId    0;
  91.         foreach ($comments as $comment{
  92.             if (!isset($authors[$comment->getAuthor()])) {
  93.                 $authors[$comment->getAuthor()$authorId++;
  94.             }
  95.         }
  96.   
  97.         // comments
  98.         $objWriter->startElement('comments');
  99.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/spreadsheetml/2006/main');
  100.             
  101.             // Loop trough authors
  102.             $objWriter->startElement('authors');
  103.             foreach ($authors as $author => $index{
  104.                 $objWriter->writeElement('author'$author);
  105.             }
  106.             $objWriter->endElement();
  107.             
  108.             // Loop trough comments
  109.             $objWriter->startElement('commentList');
  110.             foreach ($comments as $key => $value{
  111.                 $this->_writeComment($objWriter$key$value$authors);
  112.             }
  113.             $objWriter->endElement();
  114.                 
  115.         $objWriter->endElement();
  116.  
  117.         // Return
  118.         return $objWriter->getData();
  119.     }
  120.     
  121.     /**
  122.      * Write comment to XML format
  123.      *
  124.      * @param     PHPExcel_Shared_XMLWriter        $objWriter             XML Writer
  125.      * @param    string                            $pCellReference        Cell reference
  126.      * @param     PHPExcel_Comment                $pComment            Comment
  127.      * @param    array                            $pAuthors            Array of authors
  128.      * @throws     Exception
  129.      */
  130.     public function _writeComment(PHPExcel_Shared_XMLWriter $objWriter null$pCellReference 'A1'PHPExcel_Comment $pComment null$pAuthors null)
  131.     {
  132.         // comment
  133.         $objWriter->startElement('comment');
  134.         $objWriter->writeAttribute('ref',         $pCellReference);
  135.         $objWriter->writeAttribute('authorId',     $pAuthors[$pComment->getAuthor()]);
  136.         
  137.             // text
  138.             $objWriter->startElement('text');
  139.             $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter$pComment->getText());
  140.             $objWriter->endElement();
  141.         
  142.         $objWriter->endElement();
  143.     }
  144.     
  145.     /**
  146.      * Write VML comments to XML format
  147.      *
  148.      * @param     PHPExcel_Worksheet                $pWorksheet 
  149.      * @return     string                                 XML Output
  150.      * @throws     Exception
  151.      */
  152.     public function writeVMLComments(PHPExcel_Worksheet $pWorksheet null)
  153.     {
  154.         // Create XML writer
  155.         $objWriter null;
  156.         if ($this->getParentWriter()->getUseDiskCaching()) {
  157.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK);
  158.         else {
  159.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  160.         }
  161.             
  162.         // XML header
  163.         $objWriter->startDocument('1.0','UTF-8','yes');
  164.   
  165.           // Comments cache
  166.           $comments    $pWorksheet->getComments();
  167.  
  168.         // xml
  169.         $objWriter->startElement('xml');
  170.         $objWriter->writeAttribute('xmlns:v''urn:schemas-microsoft-com:vml');
  171.         $objWriter->writeAttribute('xmlns:o''urn:schemas-microsoft-com:office:office');
  172.         $objWriter->writeAttribute('xmlns:x''urn:schemas-microsoft-com:office:excel');
  173.  
  174.             // o:shapelayout
  175.             $objWriter->startElement('o:shapelayout');
  176.             $objWriter->writeAttribute('v:ext',         'edit');
  177.             
  178.                 // o:idmap
  179.                 $objWriter->startElement('o:idmap');
  180.                 $objWriter->writeAttribute('v:ext',     'edit');
  181.                 $objWriter->writeAttribute('data',         '1');
  182.                 $objWriter->endElement();
  183.             
  184.             $objWriter->endElement();
  185.             
  186.             // v:shapetype
  187.             $objWriter->startElement('v:shapetype');
  188.             $objWriter->writeAttribute('id',         '_x0000_t202');
  189.             $objWriter->writeAttribute('coordsize''21600,21600');
  190.             $objWriter->writeAttribute('o:spt',     '202');
  191.             $objWriter->writeAttribute('path',         'm,l,21600r21600,l21600,xe');
  192.             
  193.                 // v:stroke
  194.                 $objWriter->startElement('v:stroke');
  195.                 $objWriter->writeAttribute('joinstyle',     'miter');
  196.                 $objWriter->endElement();
  197.                 
  198.                 // v:path
  199.                 $objWriter->startElement('v:path');
  200.                 $objWriter->writeAttribute('gradientshapeok',     't');
  201.                 $objWriter->writeAttribute('o:connecttype',     'rect');
  202.                 $objWriter->endElement();
  203.             
  204.             $objWriter->endElement();
  205.         
  206.             // Loop trough comments
  207.             foreach ($comments as $key => $value{
  208.                 $this->_writeVMLComment($objWriter$key$value);
  209.             }
  210.                 
  211.         $objWriter->endElement();
  212.  
  213.         // Return
  214.         return $objWriter->getData();
  215.     }
  216.     
  217.     /**
  218.      * Write VML comment to XML format
  219.      *
  220.      * @param     PHPExcel_Shared_XMLWriter        $objWriter             XML Writer
  221.      * @param    string                            $pCellReference        Cell reference
  222.      * @param     PHPExcel_Comment                $pComment            Comment
  223.      * @throws     Exception
  224.      */
  225.     public function _writeVMLComment(PHPExcel_Shared_XMLWriter $objWriter null$pCellReference 'A1'PHPExcel_Comment $pComment null)
  226.     {
  227.          // Metadata
  228.          list($column$rowPHPExcel_Cell::coordinateFromString($pCellReference);
  229.          $column PHPExcel_Cell::columnIndexFromString($column);
  230.          $id 1024 $column $row;
  231.          $id substr($id04);
  232.          
  233.         // v:shape
  234.         $objWriter->startElement('v:shape');
  235.         $objWriter->writeAttribute('id',             '_x0000_s' $id);
  236.         $objWriter->writeAttribute('type',             '#_x0000_t202');
  237.         $objWriter->writeAttribute('style',         'position:absolute;margin-left:' $pComment->getMarginLeft(';margin-top:' $pComment->getMarginTop(';width:' $pComment->getWidth(';height:' $pComment->getHeight(';z-index:1;visibility:' ($pComment->getVisible('visible' 'hidden'));
  238.         $objWriter->writeAttribute('fillcolor',     '#' $pComment->getFillColor()->getRGB());
  239.         $objWriter->writeAttribute('o:insetmode',     'auto');
  240.         
  241.             // v:fill
  242.             $objWriter->startElement('v:fill');
  243.             $objWriter->writeAttribute('color2',         '#' $pComment->getFillColor()->getRGB());
  244.             $objWriter->endElement();
  245.             
  246.             // v:shadow
  247.             $objWriter->startElement('v:shadow');
  248.             $objWriter->writeAttribute('on',             't');
  249.             $objWriter->writeAttribute('color',         'black');
  250.             $objWriter->writeAttribute('obscured',         't');
  251.             $objWriter->endElement();
  252.         
  253.             // v:path
  254.             $objWriter->startElement('v:path');
  255.             $objWriter->writeAttribute('o:connecttype''none');
  256.             $objWriter->endElement();
  257.             
  258.             // v:textbox
  259.             $objWriter->startElement('v:textbox');
  260.             $objWriter->writeAttribute('style''mso-direction-alt:auto');
  261.             
  262.                 // div
  263.                 $objWriter->startElement('div');
  264.                 $objWriter->writeAttribute('style''text-align:left');
  265.                 $objWriter->endElement();
  266.             
  267.             $objWriter->endElement();
  268.             
  269.             // x:ClientData
  270.             $objWriter->startElement('x:ClientData');
  271.             $objWriter->writeAttribute('ObjectType''Note');
  272.             
  273.                 // x:MoveWithCells
  274.                 $objWriter->writeElement('x:MoveWithCells''');
  275.                 
  276.                 // x:SizeWithCells
  277.                 $objWriter->writeElement('x:SizeWithCells''');
  278.                 
  279.                 // x:Anchor
  280.                 //$objWriter->writeElement('x:Anchor', $column . ', 15, ' . ($row - 2) . ', 10, ' . ($column + 4) . ', 15, ' . ($row + 5) . ', 18');
  281.  
  282.                 // x:AutoFill
  283.                 $objWriter->writeElement('x:AutoFill''False');
  284.                 
  285.                 // x:Row
  286.                 $objWriter->writeElement('x:Row'($row 1));
  287.                 
  288.                 // x:Column
  289.                 $objWriter->writeElement('x:Column'($column 1));
  290.             
  291.             $objWriter->endElement();  
  292.         
  293.         $objWriter->endElement();
  294.     }
  295. }

Documentation generated on Mon, 05 Jan 2009 20:36:42 +0100 by phpDocumentor 1.4.1