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