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
using System;
using System.Xml.Linq;
 
namespace Novacode
{
    public class PageLayout: DocXElement
    {
        internal PageLayout(DocX document, XElement xml):base(document, xml)
        {
        
        }
 
        
        public Orientation Orientation 
        {
            get
            {
                /*
                 * Get the pgSz (page size) element for this Section,
                 * null will be return if no such element exists.
                 */
                XElement pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
 
                if (pgSz == null)
                    return Orientation.Portrait;
 
                // Get the attribute of the pgSz element.
                XAttribute val = pgSz.Attribute(XName.Get("orient", DocX.w.NamespaceName));
 
                // If val is null, this cell contains no information.
                if (val == null)
                    return Orientation.Portrait;
 
                if (val.Value.Equals("Landscape", StringComparison.CurrentCultureIgnoreCase))
                    return Orientation.Landscape;
                else
                    return Orientation.Portrait;
            }
 
            set
            {
                // Check if already correct value.
                if (Orientation == value)
                    return;
 
                /*
                 * Get the pgSz (page size) element for this Section,
                 * null will be return if no such element exists.
                 */
                XElement pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
 
                if (pgSz == null)
                {
                    Xml.SetElementValue(XName.Get("pgSz", DocX.w.NamespaceName), string.Empty);
                    pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
                }
 
                pgSz.SetAttributeValue(XName.Get("orient", DocX.w.NamespaceName), value.ToString().ToLower());
 
                if(value == Novacode.Orientation.Landscape)
                {
                    pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), "16838");
                    pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), "11906");
                }
 
                else if (value == Novacode.Orientation.Portrait)
                {
                    pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), "11906");
                    pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), "16838");
                }
            }
        }
    }
}