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

Documentation generated on Sun, 27 Feb 2011 16:29:09 -0800 by phpDocumentor 1.4.3