Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PageLayout.cs 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. namespace Novacode
  7. {
  8. public class PageLayout: DocXElement
  9. {
  10. internal PageLayout(DocX document, XElement xml):base(document, xml)
  11. {
  12. }
  13. public Orientation Orientation
  14. {
  15. get
  16. {
  17. /*
  18. * Get the pgSz (page size) element for this Section,
  19. * null will be return if no such element exists.
  20. */
  21. XElement pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
  22. if (pgSz == null)
  23. return Orientation.Portrait;
  24. // Get the attribute of the pgSz element.
  25. XAttribute val = pgSz.Attribute(XName.Get("orient", DocX.w.NamespaceName));
  26. // If val is null, this cell contains no information.
  27. if (val == null)
  28. return Orientation.Portrait;
  29. if (val.Value.Equals("Landscape", StringComparison.CurrentCultureIgnoreCase))
  30. return Orientation.Landscape;
  31. else
  32. return Orientation.Portrait;
  33. }
  34. set
  35. {
  36. // Check if already correct value.
  37. if (Orientation == value)
  38. return;
  39. /*
  40. * Get the pgSz (page size) element for this Section,
  41. * null will be return if no such element exists.
  42. */
  43. XElement pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
  44. if (pgSz == null)
  45. {
  46. Xml.SetElementValue(XName.Get("pgSz", DocX.w.NamespaceName), string.Empty);
  47. pgSz = Xml.Element(XName.Get("pgSz", DocX.w.NamespaceName));
  48. }
  49. pgSz.SetAttributeValue(XName.Get("orient", DocX.w.NamespaceName), value.ToString().ToLower());
  50. if(value == Novacode.Orientation.Landscape)
  51. {
  52. pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), "16838");
  53. pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), "11906");
  54. }
  55. else if (value == Novacode.Orientation.Portrait)
  56. {
  57. pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), "11906");
  58. pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), "16838");
  59. }
  60. }
  61. }
  62. }
  63. }