| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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");
- }
- }
- }
- }
- }
|