Subversion Repositories eFlore/Applications.cel

Rev

Rev 2388 | Details | Compare with Previous | Last modification | View Log | RSS feed

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