1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | * ******************************************************************************
|
---|
29 | * Jan Källman Initial Release 2009-10-01
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-27
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Text;
|
---|
35 | using System.Xml;
|
---|
36 | using System.Globalization;
|
---|
37 |
|
---|
38 | namespace OfficeOpenXml
|
---|
39 | {
|
---|
40 | #region "Enums"
|
---|
41 | /// <summary>
|
---|
42 | /// Printer orientation
|
---|
43 | /// </summary>
|
---|
44 | public enum eOrientation
|
---|
45 | {
|
---|
46 | /// <summary>
|
---|
47 | /// Portrait orientation
|
---|
48 | /// </summary>
|
---|
49 | Portrait,
|
---|
50 | /// <summary>
|
---|
51 | /// Landscape orientation
|
---|
52 | /// </summary>
|
---|
53 | Landscape
|
---|
54 | }
|
---|
55 | /// <summary>
|
---|
56 | /// Papersize
|
---|
57 | /// </summary>
|
---|
58 | public enum ePaperSize
|
---|
59 | {
|
---|
60 | /// <summary>
|
---|
61 | /// Letter paper (8.5 in. by 11 in.)
|
---|
62 | /// </summary>
|
---|
63 | Letter= 1,
|
---|
64 | /// <summary>
|
---|
65 | /// Letter small paper (8.5 in. by 11 in.)
|
---|
66 | /// </summary>
|
---|
67 | LetterSmall=2,
|
---|
68 | /// <summary>
|
---|
69 | /// // Tabloid paper (11 in. by 17 in.)
|
---|
70 | /// </summary>
|
---|
71 | Tabloid=3,
|
---|
72 | /// <summary>
|
---|
73 | /// Ledger paper (17 in. by 11 in.)
|
---|
74 | /// </summary>
|
---|
75 | Ledger=4,
|
---|
76 | /// <summary>
|
---|
77 | /// Legal paper (8.5 in. by 14 in.)
|
---|
78 | /// </summary>
|
---|
79 | Legal=5,
|
---|
80 | /// <summary>
|
---|
81 | /// Statement paper (5.5 in. by 8.5 in.)
|
---|
82 | /// </summary>
|
---|
83 | Statement=6,
|
---|
84 | /// <summary>
|
---|
85 | /// Executive paper (7.25 in. by 10.5 in.)
|
---|
86 | /// </summary>
|
---|
87 | Executive=7,
|
---|
88 | /// <summary>
|
---|
89 | /// A3 paper (297 mm by 420 mm)
|
---|
90 | /// </summary>
|
---|
91 | A3=8,
|
---|
92 | /// <summary>
|
---|
93 | /// A4 paper (210 mm by 297 mm)
|
---|
94 | /// </summary>
|
---|
95 | A4=9,
|
---|
96 | /// <summary>
|
---|
97 | /// A4 small paper (210 mm by 297 mm)
|
---|
98 | /// </summary>
|
---|
99 | A4Small=10,
|
---|
100 | /// <summary>
|
---|
101 | /// A5 paper (148 mm by 210 mm)
|
---|
102 | /// </summary>
|
---|
103 | A5=11,
|
---|
104 | /// <summary>
|
---|
105 | /// B4 paper (250 mm by 353 mm)
|
---|
106 | /// </summary>
|
---|
107 | B4=12,
|
---|
108 | /// <summary>
|
---|
109 | /// B5 paper (176 mm by 250 mm)
|
---|
110 | /// </summary>
|
---|
111 | B5=13,
|
---|
112 | /// <summary>
|
---|
113 | /// Folio paper (8.5 in. by 13 in.)
|
---|
114 | /// </summary>
|
---|
115 | Folio=14,
|
---|
116 | /// <summary>
|
---|
117 | /// Quarto paper (215 mm by 275 mm)
|
---|
118 | /// </summary>
|
---|
119 | Quarto=15,
|
---|
120 | /// <summary>
|
---|
121 | /// Standard paper (10 in. by 14 in.)
|
---|
122 | /// </summary>
|
---|
123 | Standard10_14=16,
|
---|
124 | /// <summary>
|
---|
125 | /// Standard paper (11 in. by 17 in.)
|
---|
126 | /// </summary>
|
---|
127 | Standard11_17=17,
|
---|
128 | /// <summary>
|
---|
129 | /// Note paper (8.5 in. by 11 in.)
|
---|
130 | /// </summary>
|
---|
131 | Note=18,
|
---|
132 | /// <summary>
|
---|
133 | /// #9 envelope (3.875 in. by 8.875 in.)
|
---|
134 | /// </summary>
|
---|
135 | Envelope9=19,
|
---|
136 | /// <summary>
|
---|
137 | /// #10 envelope (4.125 in. by 9.5 in.)
|
---|
138 | /// </summary>
|
---|
139 | Envelope10=20,
|
---|
140 | /// <summary>
|
---|
141 | /// #11 envelope (4.5 in. by 10.375 in.)
|
---|
142 | /// </summary>
|
---|
143 | Envelope11=21,
|
---|
144 | /// <summary>
|
---|
145 | /// #12 envelope (4.75 in. by 11 in.)
|
---|
146 | /// </summary>
|
---|
147 | Envelope12=22,
|
---|
148 | /// <summary>
|
---|
149 | /// #14 envelope (5 in. by 11.5 in.)
|
---|
150 | /// </summary>
|
---|
151 | Envelope14=23,
|
---|
152 | /// <summary>
|
---|
153 | /// C paper (17 in. by 22 in.)
|
---|
154 | /// </summary>
|
---|
155 | C=24,
|
---|
156 | /// <summary>
|
---|
157 | /// D paper (22 in. by 34 in.)
|
---|
158 | /// </summary>
|
---|
159 | D=25,
|
---|
160 | /// <summary>
|
---|
161 | /// E paper (34 in. by 44 in.)
|
---|
162 | /// </summary>
|
---|
163 | E=26,
|
---|
164 | /// <summary>
|
---|
165 | /// DL envelope (110 mm by 220 mm)
|
---|
166 | /// </summary>
|
---|
167 | DLEnvelope = 27,
|
---|
168 | /// <summary>
|
---|
169 | /// C5 envelope (162 mm by 229 mm)
|
---|
170 | /// </summary>
|
---|
171 | C5Envelope = 28,
|
---|
172 | /// <summary>
|
---|
173 | /// C3 envelope (324 mm by 458 mm)
|
---|
174 | /// </summary>
|
---|
175 | C3Envelope = 29,
|
---|
176 | /// <summary>
|
---|
177 | /// C4 envelope (229 mm by 324 mm)
|
---|
178 | /// </summary>
|
---|
179 | C4Envelope = 30,
|
---|
180 | /// <summary>
|
---|
181 | /// C6 envelope (114 mm by 162 mm)
|
---|
182 | /// </summary>
|
---|
183 | C6Envelope = 31,
|
---|
184 | /// <summary>
|
---|
185 | /// C65 envelope (114 mm by 229 mm)
|
---|
186 | /// </summary>
|
---|
187 | C65Envelope = 32,
|
---|
188 | /// <summary>
|
---|
189 | /// B4 envelope (250 mm by 353 mm)
|
---|
190 | /// </summary>
|
---|
191 | B4Envelope= 33,
|
---|
192 | /// <summary>
|
---|
193 | /// B5 envelope (176 mm by 250 mm)
|
---|
194 | /// </summary>
|
---|
195 | B5Envelope= 34,
|
---|
196 | /// <summary>
|
---|
197 | /// B6 envelope (176 mm by 125 mm)
|
---|
198 | /// </summary>
|
---|
199 | B6Envelope = 35,
|
---|
200 | /// <summary>
|
---|
201 | /// Italy envelope (110 mm by 230 mm)
|
---|
202 | /// </summary>
|
---|
203 | ItalyEnvelope = 36,
|
---|
204 | /// <summary>
|
---|
205 | /// Monarch envelope (3.875 in. by 7.5 in.).
|
---|
206 | /// </summary>
|
---|
207 | MonarchEnvelope = 37,
|
---|
208 | /// <summary>
|
---|
209 | /// 6 3/4 envelope (3.625 in. by 6.5 in.)
|
---|
210 | /// </summary>
|
---|
211 | Six3_4Envelope = 38,
|
---|
212 | /// <summary>
|
---|
213 | /// US standard fanfold (14.875 in. by 11 in.)
|
---|
214 | /// </summary>
|
---|
215 | USStandard=39,
|
---|
216 | /// <summary>
|
---|
217 | /// German standard fanfold (8.5 in. by 12 in.)
|
---|
218 | /// </summary>
|
---|
219 | GermanStandard=40,
|
---|
220 | /// <summary>
|
---|
221 | /// German legal fanfold (8.5 in. by 13 in.)
|
---|
222 | /// </summary>
|
---|
223 | GermanLegal=41,
|
---|
224 | /// <summary>
|
---|
225 | /// ISO B4 (250 mm by 353 mm)
|
---|
226 | /// </summary>
|
---|
227 | ISOB4=42,
|
---|
228 | /// <summary>
|
---|
229 | /// Japanese double postcard (200 mm by 148 mm)
|
---|
230 | /// </summary>
|
---|
231 | JapaneseDoublePostcard=43,
|
---|
232 | /// <summary>
|
---|
233 | /// Standard paper (9 in. by 11 in.)
|
---|
234 | /// </summary>
|
---|
235 | Standard9=44,
|
---|
236 | /// <summary>
|
---|
237 | /// Standard paper (10 in. by 11 in.)
|
---|
238 | /// </summary>
|
---|
239 | Standard10=45,
|
---|
240 | /// <summary>
|
---|
241 | /// Standard paper (15 in. by 11 in.)
|
---|
242 | /// </summary>
|
---|
243 | Standard15=46,
|
---|
244 | /// <summary>
|
---|
245 | /// Invite envelope (220 mm by 220 mm)
|
---|
246 | /// </summary>
|
---|
247 | InviteEnvelope = 47,
|
---|
248 | /// <summary>
|
---|
249 | /// Letter extra paper (9.275 in. by 12 in.)
|
---|
250 | /// </summary>
|
---|
251 | LetterExtra=50,
|
---|
252 | /// <summary>
|
---|
253 | /// Legal extra paper (9.275 in. by 15 in.)
|
---|
254 | /// </summary>
|
---|
255 | LegalExtra=51,
|
---|
256 | /// <summary>
|
---|
257 | /// Tabloid extra paper (11.69 in. by 18 in.)
|
---|
258 | /// </summary>
|
---|
259 | TabloidExtra=52,
|
---|
260 | /// <summary>
|
---|
261 | /// A4 extra paper (236 mm by 322 mm)
|
---|
262 | /// </summary>
|
---|
263 | A4Extra=53,
|
---|
264 | /// <summary>
|
---|
265 | /// Letter transverse paper (8.275 in. by 11 in.)
|
---|
266 | /// </summary>
|
---|
267 | LetterTransverse=54,
|
---|
268 | /// <summary>
|
---|
269 | /// A4 transverse paper (210 mm by 297 mm)
|
---|
270 | /// </summary>
|
---|
271 | A4Transverse=55,
|
---|
272 | /// <summary>
|
---|
273 | /// Letter extra transverse paper (9.275 in. by 12 in.)
|
---|
274 | /// </summary>
|
---|
275 | LetterExtraTransverse=56,
|
---|
276 | /// <summary>
|
---|
277 | /// SuperA/SuperA/A4 paper (227 mm by 356 mm)
|
---|
278 | /// </summary>
|
---|
279 | SuperA=57,
|
---|
280 | /// <summary>
|
---|
281 | /// SuperB/SuperB/A3 paper (305 mm by 487 mm)
|
---|
282 | /// </summary>
|
---|
283 | SuperB=58,
|
---|
284 | /// <summary>
|
---|
285 | /// Letter plus paper (8.5 in. by 12.69 in.)
|
---|
286 | /// </summary>
|
---|
287 | LetterPlus=59,
|
---|
288 | /// <summary>
|
---|
289 | /// A4 plus paper (210 mm by 330 mm)
|
---|
290 | /// </summary>
|
---|
291 | A4Plus=60,
|
---|
292 | /// <summary>
|
---|
293 | /// A5 transverse paper (148 mm by 210 mm)
|
---|
294 | /// </summary>
|
---|
295 | A5Transverse=61,
|
---|
296 | /// <summary>
|
---|
297 | /// JIS B5 transverse paper (182 mm by 257 mm)
|
---|
298 | /// </summary>
|
---|
299 | JISB5Transverse=62,
|
---|
300 | /// <summary>
|
---|
301 | /// A3 extra paper (322 mm by 445 mm)
|
---|
302 | /// </summary>
|
---|
303 | A3Extra=63,
|
---|
304 | /// <summary>
|
---|
305 | /// A5 extra paper (174 mm by 235 mm)
|
---|
306 | /// </summary>
|
---|
307 | A5Extra=64,
|
---|
308 | /// <summary>
|
---|
309 | /// ISO B5 extra paper (201 mm by 276 mm)
|
---|
310 | /// </summary>
|
---|
311 | ISOB5=65,
|
---|
312 | /// <summary>
|
---|
313 | /// A2 paper (420 mm by 594 mm)
|
---|
314 | /// </summary>
|
---|
315 | A2=66,
|
---|
316 | /// <summary>
|
---|
317 | /// A3 transverse paper (297 mm by 420 mm)
|
---|
318 | /// </summary>
|
---|
319 | A3Transverse=67,
|
---|
320 | /// <summary>
|
---|
321 | /// A3 extra transverse paper (322 mm by 445 mm*/
|
---|
322 | /// </summary>
|
---|
323 | A3ExtraTransverse = 68
|
---|
324 | }
|
---|
325 | /// <summary>
|
---|
326 | /// Specifies printed page order
|
---|
327 | /// </summary>
|
---|
328 | public enum ePageOrder
|
---|
329 | {
|
---|
330 |
|
---|
331 | /// <summary>
|
---|
332 | /// Order pages vertically first, then move horizontally.
|
---|
333 | /// </summary>
|
---|
334 | DownThenOver,
|
---|
335 | /// <summary>
|
---|
336 | /// Order pages horizontally first, then move vertically
|
---|
337 | /// </summary>
|
---|
338 | OverThenDown
|
---|
339 | }
|
---|
340 | #endregion
|
---|
341 | /// <summary>
|
---|
342 | /// Printer settings
|
---|
343 | /// </summary>
|
---|
344 | public sealed class ExcelPrinterSettings : XmlHelper
|
---|
345 | {
|
---|
346 | ExcelWorksheet _ws;
|
---|
347 | bool _marginsCreated = false;
|
---|
348 |
|
---|
349 | internal ExcelPrinterSettings(XmlNamespaceManager ns, XmlNode topNode,ExcelWorksheet ws) :
|
---|
350 | base(ns, topNode)
|
---|
351 | {
|
---|
352 | _ws = ws;
|
---|
353 | SchemaNodeOrder = ws.SchemaNodeOrder;
|
---|
354 | }
|
---|
355 | const string _leftMarginPath = "d:pageMargins/@left";
|
---|
356 | /// <summary>
|
---|
357 | /// Left margin in inches
|
---|
358 | /// </summary>
|
---|
359 | public decimal LeftMargin
|
---|
360 | {
|
---|
361 | get
|
---|
362 | {
|
---|
363 | return GetXmlNodeDecimal(_leftMarginPath);
|
---|
364 | }
|
---|
365 | set
|
---|
366 | {
|
---|
367 | CreateMargins();
|
---|
368 | SetXmlNodeString(_leftMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
369 | }
|
---|
370 | }
|
---|
371 | const string _rightMarginPath = "d:pageMargins/@right";
|
---|
372 | /// <summary>
|
---|
373 | /// Right margin in inches
|
---|
374 | /// </summary>
|
---|
375 | public decimal RightMargin
|
---|
376 | {
|
---|
377 | get
|
---|
378 | {
|
---|
379 | return GetXmlNodeDecimal(_rightMarginPath);
|
---|
380 | }
|
---|
381 | set
|
---|
382 | {
|
---|
383 | CreateMargins();
|
---|
384 | SetXmlNodeString(_rightMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
385 | }
|
---|
386 | }
|
---|
387 | const string _topMarginPath = "d:pageMargins/@top";
|
---|
388 | /// <summary>
|
---|
389 | /// Top margin in inches
|
---|
390 | /// </summary>
|
---|
391 | public decimal TopMargin
|
---|
392 | {
|
---|
393 | get
|
---|
394 | {
|
---|
395 | return GetXmlNodeDecimal(_topMarginPath);
|
---|
396 | }
|
---|
397 | set
|
---|
398 | {
|
---|
399 | CreateMargins();
|
---|
400 | SetXmlNodeString(_topMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
401 | }
|
---|
402 | }
|
---|
403 | const string _bottomMarginPath = "d:pageMargins/@bottom";
|
---|
404 | /// <summary>
|
---|
405 | /// Bottom margin in inches
|
---|
406 | /// </summary>
|
---|
407 | public decimal BottomMargin
|
---|
408 | {
|
---|
409 | get
|
---|
410 | {
|
---|
411 | return GetXmlNodeDecimal(_bottomMarginPath);
|
---|
412 | }
|
---|
413 | set
|
---|
414 | {
|
---|
415 | CreateMargins();
|
---|
416 | SetXmlNodeString(_bottomMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
417 | }
|
---|
418 | }
|
---|
419 | const string _headerMarginPath = "d:pageMargins/@header";
|
---|
420 | /// <summary>
|
---|
421 | /// Header margin in inches
|
---|
422 | /// </summary>
|
---|
423 | public decimal HeaderMargin
|
---|
424 | {
|
---|
425 | get
|
---|
426 | {
|
---|
427 | return GetXmlNodeDecimal(_headerMarginPath);
|
---|
428 | }
|
---|
429 | set
|
---|
430 | {
|
---|
431 | CreateMargins();
|
---|
432 | SetXmlNodeString(_headerMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
433 | }
|
---|
434 | }
|
---|
435 | const string _footerMarginPath = "d:pageMargins/@footer";
|
---|
436 | /// <summary>
|
---|
437 | /// Footer margin in inches
|
---|
438 | /// </summary>
|
---|
439 | public decimal FooterMargin
|
---|
440 | {
|
---|
441 | get
|
---|
442 | {
|
---|
443 | return GetXmlNodeDecimal(_footerMarginPath);
|
---|
444 | }
|
---|
445 | set
|
---|
446 | {
|
---|
447 | CreateMargins();
|
---|
448 | SetXmlNodeString(_footerMarginPath, value.ToString(CultureInfo.InvariantCulture));
|
---|
449 | }
|
---|
450 | }
|
---|
451 | const string _orientationPath = "d:pageSetup/@orientation";
|
---|
452 | /// <summary>
|
---|
453 | /// Orientation
|
---|
454 | /// Portrait or Landscape
|
---|
455 | /// </summary>
|
---|
456 | public eOrientation Orientation
|
---|
457 | {
|
---|
458 | get
|
---|
459 | {
|
---|
460 | return (eOrientation)Enum.Parse(typeof(eOrientation), GetXmlNodeString(_orientationPath), true);
|
---|
461 | }
|
---|
462 | set
|
---|
463 | {
|
---|
464 | SetXmlNodeString(_orientationPath, value.ToString().ToLower(CultureInfo.InvariantCulture));
|
---|
465 | }
|
---|
466 | }
|
---|
467 | const string _fitToWidthPath = "d:pageSetup/@fitToWidth";
|
---|
468 | /// <summary>
|
---|
469 | /// Fit to Width in pages.
|
---|
470 | /// Set FitToPage to true when using this one.
|
---|
471 | /// 0 is automatic
|
---|
472 | /// </summary>
|
---|
473 | public int FitToWidth
|
---|
474 | {
|
---|
475 | get
|
---|
476 | {
|
---|
477 | return GetXmlNodeInt(_fitToWidthPath);
|
---|
478 | }
|
---|
479 | set
|
---|
480 | {
|
---|
481 | SetXmlNodeString(_fitToWidthPath, value.ToString());
|
---|
482 | }
|
---|
483 | }
|
---|
484 | const string _fitToHeightPath = "d:pageSetup/@fitToHeight";
|
---|
485 | /// <summary>
|
---|
486 | /// Fit to height in pages.
|
---|
487 | /// Set FitToPage to true when using this one.
|
---|
488 | /// 0 is automatic
|
---|
489 | /// </summary>
|
---|
490 | public int FitToHeight
|
---|
491 | {
|
---|
492 | get
|
---|
493 | {
|
---|
494 | return GetXmlNodeInt(_fitToHeightPath);
|
---|
495 | }
|
---|
496 | set
|
---|
497 | {
|
---|
498 | SetXmlNodeString(_fitToHeightPath, value.ToString());
|
---|
499 | }
|
---|
500 | }
|
---|
501 | const string _scalePath = "d:pageSetup/@scale";
|
---|
502 | /// <summary>
|
---|
503 | /// Print scale
|
---|
504 | /// </summary>
|
---|
505 | public int Scale
|
---|
506 | {
|
---|
507 | get
|
---|
508 | {
|
---|
509 | return GetXmlNodeInt(_scalePath);
|
---|
510 | }
|
---|
511 | set
|
---|
512 | {
|
---|
513 | SetXmlNodeString(_scalePath, value.ToString());
|
---|
514 | }
|
---|
515 | }
|
---|
516 | const string _fitToPagePath = "d:sheetPr/d:pageSetUpPr/@fitToPage";
|
---|
517 | /// <summary>
|
---|
518 | /// Fit To Page.
|
---|
519 | /// </summary>
|
---|
520 | public bool FitToPage
|
---|
521 | {
|
---|
522 | get
|
---|
523 | {
|
---|
524 | return GetXmlNodeBool(_fitToPagePath);
|
---|
525 | }
|
---|
526 | set
|
---|
527 | {
|
---|
528 | SetXmlNodeString(_fitToPagePath, value ? "1" : "0");
|
---|
529 | }
|
---|
530 | }
|
---|
531 | const string _headersPath = "d:printOptions/@headings";
|
---|
532 | /// <summary>
|
---|
533 | /// Print headings (column letter and row numbers)
|
---|
534 | /// </summary>
|
---|
535 | public bool ShowHeaders
|
---|
536 | {
|
---|
537 | get
|
---|
538 | {
|
---|
539 | return GetXmlNodeBool(_headersPath, false);
|
---|
540 | }
|
---|
541 | set
|
---|
542 | {
|
---|
543 | SetXmlNodeBool(_headersPath, value, false);
|
---|
544 | }
|
---|
545 | }
|
---|
546 | /// <summary>
|
---|
547 | /// Print titles
|
---|
548 | /// Rows to be repeated after each pagebreak.
|
---|
549 | /// The address must be a full row address (ex. 1:1)
|
---|
550 | /// </summary>
|
---|
551 | public ExcelAddress RepeatRows
|
---|
552 | {
|
---|
553 | get
|
---|
554 | {
|
---|
555 | if (_ws.Names.ContainsKey("_xlnm.Print_Titles"))
|
---|
556 | {
|
---|
557 | ExcelRangeBase r = _ws.Names["_xlnm.Print_Titles"] as ExcelRangeBase;
|
---|
558 | if (r.Start.Column == 1 && r.End.Column == ExcelPackage.MaxColumns)
|
---|
559 | {
|
---|
560 | return new ExcelAddress(r.FirstAddress);
|
---|
561 | }
|
---|
562 | else if (r._addresses != null && r.Addresses[0].Start.Column == 1 && r.Addresses[0].End.Column == ExcelPackage.MaxColumns)
|
---|
563 | {
|
---|
564 | return r._addresses[0];
|
---|
565 | }
|
---|
566 | else
|
---|
567 | {
|
---|
568 | return null;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | else
|
---|
572 | {
|
---|
573 | return null;
|
---|
574 | }
|
---|
575 | }
|
---|
576 | set
|
---|
577 | {
|
---|
578 |
|
---|
579 | //Must span entire columns
|
---|
580 | if (!(value.Start.Column == 1 && value.End.Column == ExcelPackage.MaxColumns))
|
---|
581 | {
|
---|
582 | throw new InvalidOperationException("Address must span full columns only (for ex. Address=\"A:A\" for the first column).");
|
---|
583 | }
|
---|
584 |
|
---|
585 | var vertAddr = RepeatColumns;
|
---|
586 | string addr;
|
---|
587 | if (vertAddr == null)
|
---|
588 | {
|
---|
589 | addr = value.Address;
|
---|
590 | }
|
---|
591 | else
|
---|
592 | {
|
---|
593 | addr = vertAddr.Address + "," + value.Address;
|
---|
594 | }
|
---|
595 |
|
---|
596 | if (_ws.Names.ContainsKey("_xlnm.Print_Titles"))
|
---|
597 | {
|
---|
598 | _ws.Names["_xlnm.Print_Titles"].Address = addr;
|
---|
599 | }
|
---|
600 | else
|
---|
601 | {
|
---|
602 | _ws.Names.Add("_xlnm.Print_Titles", new ExcelRangeBase(_ws, addr));
|
---|
603 | }
|
---|
604 | }
|
---|
605 | }
|
---|
606 | /// <summary>
|
---|
607 | /// Print titles
|
---|
608 | /// Columns to be repeated after each pagebreak.
|
---|
609 | /// The address must be a full column address (ex. A:A)
|
---|
610 | /// </summary>
|
---|
611 | public ExcelAddress RepeatColumns
|
---|
612 | {
|
---|
613 | get
|
---|
614 | {
|
---|
615 | if (_ws.Names.ContainsKey("_xlnm.Print_Titles"))
|
---|
616 | {
|
---|
617 | ExcelRangeBase r = _ws.Names["_xlnm.Print_Titles"] as ExcelRangeBase;
|
---|
618 | if (r.Start.Row == 1 && r.End.Row == ExcelPackage.MaxRows)
|
---|
619 | {
|
---|
620 | return new ExcelAddress(r.FirstAddress);
|
---|
621 | }
|
---|
622 | else if (r._addresses != null && (r._addresses[0].Start.Row == 1 && r._addresses[0].End.Row == ExcelPackage.MaxRows))
|
---|
623 | {
|
---|
624 | return r._addresses[0];
|
---|
625 | }
|
---|
626 | else
|
---|
627 | {
|
---|
628 | return null;
|
---|
629 | }
|
---|
630 | }
|
---|
631 | else
|
---|
632 | {
|
---|
633 | return null;
|
---|
634 | }
|
---|
635 | }
|
---|
636 | set
|
---|
637 | {
|
---|
638 | //Must span entire rows
|
---|
639 | if (!(value.Start.Row == 1 && value.End.Row== ExcelPackage.MaxRows))
|
---|
640 | {
|
---|
641 | throw new InvalidOperationException("Address must span rows only (for ex. Address=\"1:1\" for the first row).");
|
---|
642 | }
|
---|
643 |
|
---|
644 | var horAddr = RepeatRows;
|
---|
645 | string addr;
|
---|
646 | if (horAddr == null)
|
---|
647 | {
|
---|
648 | addr = value.Address;
|
---|
649 | }
|
---|
650 | else
|
---|
651 | {
|
---|
652 | addr = value.Address + "," + horAddr.Address;
|
---|
653 | }
|
---|
654 |
|
---|
655 | if (_ws.Names.ContainsKey("_xlnm.Print_Titles"))
|
---|
656 | {
|
---|
657 | _ws.Names["_xlnm.Print_Titles"].Address = addr;
|
---|
658 | }
|
---|
659 | else
|
---|
660 | {
|
---|
661 | _ws.Names.Add("_xlnm.Print_Titles", new ExcelRangeBase(_ws, addr));
|
---|
662 | }
|
---|
663 | }
|
---|
664 | }
|
---|
665 | /// <summary>
|
---|
666 | /// The printarea.
|
---|
667 | /// Null if no print area is set.
|
---|
668 | /// </summary>
|
---|
669 | public ExcelRangeBase PrintArea
|
---|
670 | {
|
---|
671 | get
|
---|
672 | {
|
---|
673 | if (_ws.Names.ContainsKey("_xlnm.Print_Area"))
|
---|
674 | {
|
---|
675 | return _ws.Names["_xlnm.Print_Area"];
|
---|
676 | }
|
---|
677 | else
|
---|
678 | {
|
---|
679 | return null;
|
---|
680 | }
|
---|
681 | }
|
---|
682 | set
|
---|
683 | {
|
---|
684 | if (value == null)
|
---|
685 | {
|
---|
686 | _ws.Names.Remove("_xlnm.Print_Area");
|
---|
687 | }
|
---|
688 | else if (_ws.Names.ContainsKey("_xlnm.Print_Area"))
|
---|
689 | {
|
---|
690 | _ws.Names["_xlnm.Print_Area"].Address = value.Address;
|
---|
691 | }
|
---|
692 | else
|
---|
693 | {
|
---|
694 | _ws.Names.Add("_xlnm.Print_Area", value);
|
---|
695 | }
|
---|
696 | }
|
---|
697 | }
|
---|
698 | const string _gridLinesPath = "d:printOptions/@gridLines";
|
---|
699 | /// <summary>
|
---|
700 | /// Print gridlines
|
---|
701 | /// </summary>
|
---|
702 | public bool ShowGridLines
|
---|
703 | {
|
---|
704 | get
|
---|
705 | {
|
---|
706 | return GetXmlNodeBool(_gridLinesPath, false);
|
---|
707 | }
|
---|
708 | set
|
---|
709 | {
|
---|
710 | SetXmlNodeBool(_gridLinesPath, value, false);
|
---|
711 | }
|
---|
712 | }
|
---|
713 | const string _horizontalCenteredPath = "d:printOptions/@horizontalCentered";
|
---|
714 | /// <summary>
|
---|
715 | /// Horizontal centered when printing
|
---|
716 | /// </summary>w
|
---|
717 | public bool HorizontalCentered
|
---|
718 | {
|
---|
719 | get
|
---|
720 | {
|
---|
721 | return GetXmlNodeBool(_horizontalCenteredPath, false);
|
---|
722 | }
|
---|
723 | set
|
---|
724 | {
|
---|
725 | SetXmlNodeBool(_horizontalCenteredPath, value, false);
|
---|
726 | }
|
---|
727 | }
|
---|
728 | const string _verticalCenteredPath = "d:printOptions/@verticalCentered";
|
---|
729 | /// <summary>
|
---|
730 | /// Vertical centered when printing
|
---|
731 | /// </summary>
|
---|
732 | public bool VerticalCentered
|
---|
733 | {
|
---|
734 | get
|
---|
735 | {
|
---|
736 | return GetXmlNodeBool(_verticalCenteredPath, false);
|
---|
737 | }
|
---|
738 | set
|
---|
739 | {
|
---|
740 | SetXmlNodeBool(_verticalCenteredPath, value, false);
|
---|
741 | }
|
---|
742 | }
|
---|
743 | const string _pageOrderPath = "d:pageSetup/@pageOrder";
|
---|
744 | /// <summary>
|
---|
745 | /// Specifies printed page order
|
---|
746 | /// </summary>
|
---|
747 | public ePageOrder PageOrder
|
---|
748 | {
|
---|
749 | get
|
---|
750 | {
|
---|
751 | if (GetXmlNodeString(_pageOrderPath) == "overThenDown")
|
---|
752 | {
|
---|
753 | return ePageOrder.OverThenDown;
|
---|
754 | }
|
---|
755 | else
|
---|
756 | {
|
---|
757 | return ePageOrder.DownThenOver;
|
---|
758 | }
|
---|
759 | }
|
---|
760 | set
|
---|
761 | {
|
---|
762 | if (value == ePageOrder.OverThenDown)
|
---|
763 | {
|
---|
764 | SetXmlNodeString(_pageOrderPath, "overThenDown");
|
---|
765 | }
|
---|
766 | else
|
---|
767 | {
|
---|
768 | DeleteNode(_pageOrderPath);
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 | const string _blackAndWhitePath = "d:pageSetup/@blackAndWhite";
|
---|
773 | /// <summary>
|
---|
774 | /// Print black and white
|
---|
775 | /// </summary>
|
---|
776 | public bool BlackAndWhite
|
---|
777 | {
|
---|
778 | get
|
---|
779 | {
|
---|
780 | return GetXmlNodeBool(_blackAndWhitePath, false);
|
---|
781 | }
|
---|
782 | set
|
---|
783 | {
|
---|
784 | SetXmlNodeBool(_blackAndWhitePath, value, false);
|
---|
785 | }
|
---|
786 | }
|
---|
787 | const string _draftPath = "d:pageSetup/@draft";
|
---|
788 | /// <summary>
|
---|
789 | /// Print a draft
|
---|
790 | /// </summary>
|
---|
791 | public bool Draft
|
---|
792 | {
|
---|
793 | get
|
---|
794 | {
|
---|
795 | return GetXmlNodeBool(_draftPath, false);
|
---|
796 | }
|
---|
797 | set
|
---|
798 | {
|
---|
799 | SetXmlNodeBool(_draftPath, value, false);
|
---|
800 | }
|
---|
801 | }
|
---|
802 | const string _paperSizePath = "d:pageSetup/@paperSize";
|
---|
803 | /// <summary>
|
---|
804 | /// Paper size
|
---|
805 | /// </summary>
|
---|
806 | public ePaperSize PaperSize
|
---|
807 | {
|
---|
808 | get
|
---|
809 | {
|
---|
810 | string s = GetXmlNodeString(_paperSizePath);
|
---|
811 | if (s != "")
|
---|
812 | {
|
---|
813 | return (ePaperSize)int.Parse(s);
|
---|
814 | }
|
---|
815 | else
|
---|
816 | {
|
---|
817 | return ePaperSize.Letter;
|
---|
818 |
|
---|
819 | }
|
---|
820 | }
|
---|
821 | set
|
---|
822 | {
|
---|
823 | SetXmlNodeString(_paperSizePath, ((int)value).ToString());
|
---|
824 | }
|
---|
825 | }
|
---|
826 | /// <summary>
|
---|
827 | /// All or none of the margin attributes must exist. Create all att ones.
|
---|
828 | /// </summary>
|
---|
829 | private void CreateMargins()
|
---|
830 | {
|
---|
831 | if (_marginsCreated==false && TopNode.SelectSingleNode(_leftMarginPath, NameSpaceManager) == null)
|
---|
832 | {
|
---|
833 | _marginsCreated=true;
|
---|
834 | LeftMargin = 0.7087M;
|
---|
835 | RightMargin = 0.7087M;
|
---|
836 | TopMargin = 0.7480M;
|
---|
837 | BottomMargin = 0.7480M;
|
---|
838 | HeaderMargin = 0.315M;
|
---|
839 | FooterMargin = 0.315M;
|
---|
840 | }
|
---|
841 | }
|
---|
842 | }
|
---|
843 | }
|
---|