ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Comments.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/Excel2007.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/Excel2007/WriterPart.php';
45 
47 require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
48 
50 require_once PHPEXCEL_ROOT . 'PHPExcel/Comment.php';
51 
53 require_once PHPEXCEL_ROOT . 'PHPExcel/RichText.php';
54 
56 require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
57 
59 require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
60 
62 require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/XMLWriter.php';
63 
64 
73 {
81  public function writeComments(PHPExcel_Worksheet $pWorksheet = null)
82  {
83  // Create XML writer
84  $objWriter = null;
85  if ($this->getParentWriter()->getUseDiskCaching()) {
86  $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
87  } else {
89  }
90 
91  // XML header
92  $objWriter->startDocument('1.0','UTF-8','yes');
93 
94  // Comments cache
95  $comments = $pWorksheet->getComments();
96 
97  // Authors cache
98  $authors = array();
99  $authorId = 0;
100  foreach ($comments as $comment) {
101  if (!isset($authors[$comment->getAuthor()])) {
102  $authors[$comment->getAuthor()] = $authorId++;
103  }
104  }
105 
106  // comments
107  $objWriter->startElement('comments');
108  $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
109 
110  // Loop trough authors
111  $objWriter->startElement('authors');
112  foreach ($authors as $author => $index) {
113  $objWriter->writeElement('author', $author);
114  }
115  $objWriter->endElement();
116 
117  // Loop trough comments
118  $objWriter->startElement('commentList');
119  foreach ($comments as $key => $value) {
120  $this->_writeComment($objWriter, $key, $value, $authors);
121  }
122  $objWriter->endElement();
123 
124  $objWriter->endElement();
125 
126  // Return
127  return $objWriter->getData();
128  }
129 
139  public function _writeComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null, $pAuthors = null)
140  {
141  // comment
142  $objWriter->startElement('comment');
143  $objWriter->writeAttribute('ref', $pCellReference);
144  $objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
145 
146  // text
147  $objWriter->startElement('text');
148  $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText());
149  $objWriter->endElement();
150 
151  $objWriter->endElement();
152  }
153 
161  public function writeVMLComments(PHPExcel_Worksheet $pWorksheet = null)
162  {
163  // Create XML writer
164  $objWriter = null;
165  if ($this->getParentWriter()->getUseDiskCaching()) {
166  $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
167  } else {
169  }
170 
171  // XML header
172  $objWriter->startDocument('1.0','UTF-8','yes');
173 
174  // Comments cache
175  $comments = $pWorksheet->getComments();
176 
177  // xml
178  $objWriter->startElement('xml');
179  $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
180  $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
181  $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
182 
183  // o:shapelayout
184  $objWriter->startElement('o:shapelayout');
185  $objWriter->writeAttribute('v:ext', 'edit');
186 
187  // o:idmap
188  $objWriter->startElement('o:idmap');
189  $objWriter->writeAttribute('v:ext', 'edit');
190  $objWriter->writeAttribute('data', '1');
191  $objWriter->endElement();
192 
193  $objWriter->endElement();
194 
195  // v:shapetype
196  $objWriter->startElement('v:shapetype');
197  $objWriter->writeAttribute('id', '_x0000_t202');
198  $objWriter->writeAttribute('coordsize', '21600,21600');
199  $objWriter->writeAttribute('o:spt', '202');
200  $objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe');
201 
202  // v:stroke
203  $objWriter->startElement('v:stroke');
204  $objWriter->writeAttribute('joinstyle', 'miter');
205  $objWriter->endElement();
206 
207  // v:path
208  $objWriter->startElement('v:path');
209  $objWriter->writeAttribute('gradientshapeok', 't');
210  $objWriter->writeAttribute('o:connecttype', 'rect');
211  $objWriter->endElement();
212 
213  $objWriter->endElement();
214 
215  // Loop trough comments
216  foreach ($comments as $key => $value) {
217  $this->_writeVMLComment($objWriter, $key, $value);
218  }
219 
220  $objWriter->endElement();
221 
222  // Return
223  return $objWriter->getData();
224  }
225 
234  public function _writeVMLComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null)
235  {
236  // Metadata
237  list($column, $row) = PHPExcel_Cell::coordinateFromString($pCellReference);
238  $column = PHPExcel_Cell::columnIndexFromString($column);
239  $id = 1024 + $column + $row;
240  $id = substr($id, 0, 4);
241 
242  // v:shape
243  $objWriter->startElement('v:shape');
244  $objWriter->writeAttribute('id', '_x0000_s' . $id);
245  $objWriter->writeAttribute('type', '#_x0000_t202');
246  $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'));
247  $objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB());
248  $objWriter->writeAttribute('o:insetmode', 'auto');
249 
250  // v:fill
251  $objWriter->startElement('v:fill');
252  $objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB());
253  $objWriter->endElement();
254 
255  // v:shadow
256  $objWriter->startElement('v:shadow');
257  $objWriter->writeAttribute('on', 't');
258  $objWriter->writeAttribute('color', 'black');
259  $objWriter->writeAttribute('obscured', 't');
260  $objWriter->endElement();
261 
262  // v:path
263  $objWriter->startElement('v:path');
264  $objWriter->writeAttribute('o:connecttype', 'none');
265  $objWriter->endElement();
266 
267  // v:textbox
268  $objWriter->startElement('v:textbox');
269  $objWriter->writeAttribute('style', 'mso-direction-alt:auto');
270 
271  // div
272  $objWriter->startElement('div');
273  $objWriter->writeAttribute('style', 'text-align:left');
274  $objWriter->endElement();
275 
276  $objWriter->endElement();
277 
278  // x:ClientData
279  $objWriter->startElement('x:ClientData');
280  $objWriter->writeAttribute('ObjectType', 'Note');
281 
282  // x:MoveWithCells
283  $objWriter->writeElement('x:MoveWithCells', '');
284 
285  // x:SizeWithCells
286  $objWriter->writeElement('x:SizeWithCells', '');
287 
288  // x:Anchor
289  //$objWriter->writeElement('x:Anchor', $column . ', 15, ' . ($row - 2) . ', 10, ' . ($column + 4) . ', 15, ' . ($row + 5) . ', 18');
290 
291  // x:AutoFill
292  $objWriter->writeElement('x:AutoFill', 'False');
293 
294  // x:Row
295  $objWriter->writeElement('x:Row', ($row - 1));
296 
297  // x:Column
298  $objWriter->writeElement('x:Column', ($column - 1));
299 
300  $objWriter->endElement();
301 
302  $objWriter->endElement();
303  }
304 }