npoi
957 строк · 24.6 Кб
1using NPOI.OpenXml4Net.Util;
2using System;
3using System.IO;
4using System.Xml;
5using System.Xml.Serialization;
6
7namespace NPOI.OpenXmlFormats.Wordprocessing
8{
9
10[Serializable]
11
12[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
13[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
14public class CT_PageSz
15{
16
17private ulong wField;
18
19private bool wFieldSpecified;
20
21private ulong hField;
22
23private bool hFieldSpecified;
24
25private ST_PageOrientation orientField;
26
27private bool orientFieldSpecified;
28
29private string codeField;
30public static CT_PageSz Parse(XmlNode node, XmlNamespaceManager namespaceManager)
31{
32if (node == null)
33return null;
34CT_PageSz ctObj = new CT_PageSz();
35ctObj.w = XmlHelper.ReadULong(node.Attributes["w:w"]);
36ctObj.h = XmlHelper.ReadULong(node.Attributes["w:h"]);
37if (node.Attributes["w:orient"] != null)
38ctObj.orient = (ST_PageOrientation)Enum.Parse(typeof(ST_PageOrientation), node.Attributes["w:orient"].Value);
39ctObj.code = XmlHelper.ReadString(node.Attributes["w:code"]);
40return ctObj;
41}
42
43
44
45internal void Write(StreamWriter sw, string nodeName)
46{
47sw.Write(string.Format("<w:{0}", nodeName));
48XmlHelper.WriteAttribute(sw, "w:w", this.w);
49XmlHelper.WriteAttribute(sw, "w:h", this.h);
50if( this.orientField!= ST_PageOrientation.portrait)
51XmlHelper.WriteAttribute(sw, "w:orient", this.orient.ToString());
52XmlHelper.WriteAttribute(sw, "w:code", this.code);
53sw.Write("/>");
54}
55
56[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
57public ulong w
58{
59get
60{
61return this.wField;
62}
63set
64{
65this.wField = value;
66}
67}
68
69[XmlIgnore]
70public bool wSpecified
71{
72get
73{
74return this.wFieldSpecified;
75}
76set
77{
78this.wFieldSpecified = value;
79}
80}
81
82[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
83public ulong h
84{
85get
86{
87return this.hField;
88}
89set
90{
91this.hField = value;
92}
93}
94
95[XmlIgnore]
96public bool hSpecified
97{
98get
99{
100return this.hFieldSpecified;
101}
102set
103{
104this.hFieldSpecified = value;
105}
106}
107
108[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
109public ST_PageOrientation orient
110{
111get
112{
113return this.orientField;
114}
115set
116{
117this.orientField = value;
118}
119}
120
121[XmlIgnore]
122public bool orientSpecified
123{
124get
125{
126return this.orientFieldSpecified;
127}
128set
129{
130this.orientFieldSpecified = value;
131}
132}
133
134[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
135public string code
136{
137get
138{
139return this.codeField;
140}
141set
142{
143this.codeField = value;
144}
145}
146}
147
148
149[Serializable]
150[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
151public enum ST_PageOrientation
152{
153
154
155portrait,
156
157
158landscape,
159}
160
161
162[Serializable]
163
164[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
165[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
166public class CT_PageMar
167{
168
169private ulong topField;
170
171private ulong rightField;
172
173private ulong bottomField;
174
175private ulong leftField;
176
177private ulong headerField;
178
179private ulong footerField;
180
181private ulong gutterField;
182
183public static CT_PageMar Parse(XmlNode node, XmlNamespaceManager namespaceManager)
184{
185if (node == null)
186return null;
187CT_PageMar ctObj = new CT_PageMar();
188ctObj.top = XmlHelper.ReadULong(node.Attributes["w:top"]);
189ctObj.right = XmlHelper.ReadULong(node.Attributes["w:right"]);
190ctObj.bottom = XmlHelper.ReadULong(node.Attributes["w:bottom"]);
191ctObj.left = XmlHelper.ReadULong(node.Attributes["w:left"]);
192ctObj.header = XmlHelper.ReadULong(node.Attributes["w:header"]);
193ctObj.footer = XmlHelper.ReadULong(node.Attributes["w:footer"]);
194ctObj.gutter = XmlHelper.ReadULong(node.Attributes["w:gutter"]);
195return ctObj;
196}
197
198
199
200internal void Write(StreamWriter sw, string nodeName)
201{
202sw.Write(string.Format("<w:{0}", nodeName));
203XmlHelper.WriteAttribute(sw, "w:top", this.top);
204XmlHelper.WriteAttribute(sw, "w:right", this.right);
205XmlHelper.WriteAttribute(sw, "w:bottom", this.bottom);
206XmlHelper.WriteAttribute(sw, "w:left", this.left);
207XmlHelper.WriteAttribute(sw, "w:header", this.header);
208XmlHelper.WriteAttribute(sw, "w:footer", this.footer);
209XmlHelper.WriteAttribute(sw, "w:gutter", this.gutter, true);
210sw.Write("/>");
211}
212
213[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
214public ulong top
215{
216get
217{
218return this.topField;
219}
220set
221{
222this.topField = value;
223}
224}
225
226[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
227public ulong right
228{
229get
230{
231return this.rightField;
232}
233set
234{
235this.rightField = value;
236}
237}
238
239[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
240public ulong bottom
241{
242get
243{
244return this.bottomField;
245}
246set
247{
248this.bottomField = value;
249}
250}
251
252[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
253public ulong left
254{
255get
256{
257return this.leftField;
258}
259set
260{
261this.leftField = value;
262}
263}
264
265[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
266public ulong header
267{
268get
269{
270return this.headerField;
271}
272set
273{
274this.headerField = value;
275}
276}
277
278[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
279public ulong footer
280{
281get
282{
283return this.footerField;
284}
285set
286{
287this.footerField = value;
288}
289}
290
291public ulong gutter
292{
293get
294{
295return this.gutterField;
296}
297set
298{
299this.gutterField = value;
300}
301}
302}
303
304
305[Serializable]
306
307[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
308[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
309public class CT_PaperSource
310{
311
312private string firstField;
313
314private string otherField;
315public static CT_PaperSource Parse(XmlNode node, XmlNamespaceManager namespaceManager)
316{
317if (node == null)
318return null;
319CT_PaperSource ctObj = new CT_PaperSource();
320ctObj.first = XmlHelper.ReadString(node.Attributes["w:first"]);
321ctObj.other = XmlHelper.ReadString(node.Attributes["w:other"]);
322return ctObj;
323}
324
325
326
327internal void Write(StreamWriter sw, string nodeName)
328{
329sw.Write(string.Format("<w:{0}", nodeName));
330XmlHelper.WriteAttribute(sw, "w:first", this.first);
331XmlHelper.WriteAttribute(sw, "w:other", this.other);
332sw.Write(">");
333sw.WriteEndW(nodeName);
334}
335
336[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
337public string first
338{
339get
340{
341return this.firstField;
342}
343set
344{
345this.firstField = value;
346}
347}
348
349[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
350public string other
351{
352get
353{
354return this.otherField;
355}
356set
357{
358this.otherField = value;
359}
360}
361}
362
363
364[Serializable]
365
366[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
367[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
368public class CT_PageBorders
369{
370
371private CT_Border topField;
372
373private CT_Border leftField;
374
375private CT_Border bottomField;
376
377private CT_Border rightField;
378
379private ST_PageBorderZOrder zOrderField;
380
381private bool zOrderFieldSpecified;
382
383private ST_PageBorderDisplay displayField;
384
385private bool displayFieldSpecified;
386
387private ST_PageBorderOffset offsetFromField;
388
389private bool offsetFromFieldSpecified;
390
391public CT_PageBorders()
392{
393//this.rightField = new CT_Border();
394//this.bottomField = new CT_Border();
395//this.leftField = new CT_Border();
396//this.topField = new CT_Border();
397}
398public static CT_PageBorders Parse(XmlNode node, XmlNamespaceManager namespaceManager)
399{
400if (node == null)
401return null;
402CT_PageBorders ctObj = new CT_PageBorders();
403if (node.Attributes["w:zOrder"] != null)
404ctObj.zOrder = (ST_PageBorderZOrder)Enum.Parse(typeof(ST_PageBorderZOrder), node.Attributes["w:zOrder"].Value);
405if (node.Attributes["w:display"] != null)
406ctObj.display = (ST_PageBorderDisplay)Enum.Parse(typeof(ST_PageBorderDisplay), node.Attributes["w:display"].Value);
407if (node.Attributes["w:offsetFrom"] != null)
408ctObj.offsetFrom = (ST_PageBorderOffset)Enum.Parse(typeof(ST_PageBorderOffset), node.Attributes["w:offsetFrom"].Value);
409foreach (XmlNode childNode in node.ChildNodes)
410{
411if (childNode.LocalName == "top")
412ctObj.top = CT_Border.Parse(childNode, namespaceManager);
413else if (childNode.LocalName == "left")
414ctObj.left = CT_Border.Parse(childNode, namespaceManager);
415else if (childNode.LocalName == "bottom")
416ctObj.bottom = CT_Border.Parse(childNode, namespaceManager);
417else if (childNode.LocalName == "right")
418ctObj.right = CT_Border.Parse(childNode, namespaceManager);
419}
420return ctObj;
421}
422
423
424
425internal void Write(StreamWriter sw, string nodeName)
426{
427sw.Write(string.Format("<w:{0}", nodeName));
428XmlHelper.WriteAttribute(sw, "w:zOrder", this.zOrder.ToString());
429XmlHelper.WriteAttribute(sw, "w:display", this.display.ToString());
430XmlHelper.WriteAttribute(sw, "w:offsetFrom", this.offsetFrom.ToString());
431sw.Write(">");
432if (this.top != null)
433this.top.Write(sw, "top");
434if (this.left != null)
435this.left.Write(sw, "left");
436if (this.bottom != null)
437this.bottom.Write(sw, "bottom");
438if (this.right != null)
439this.right.Write(sw, "right");
440sw.WriteEndW(nodeName);
441}
442
443
444[XmlElement(Order = 0)]
445public CT_Border top
446{
447get
448{
449return this.topField;
450}
451set
452{
453this.topField = value;
454}
455}
456
457[XmlElement(Order = 1)]
458public CT_Border left
459{
460get
461{
462return this.leftField;
463}
464set
465{
466this.leftField = value;
467}
468}
469
470[XmlElement(Order = 2)]
471public CT_Border bottom
472{
473get
474{
475return this.bottomField;
476}
477set
478{
479this.bottomField = value;
480}
481}
482
483[XmlElement(Order = 3)]
484public CT_Border right
485{
486get
487{
488return this.rightField;
489}
490set
491{
492this.rightField = value;
493}
494}
495
496[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
497public ST_PageBorderZOrder zOrder
498{
499get
500{
501return this.zOrderField;
502}
503set
504{
505this.zOrderField = value;
506}
507}
508
509[XmlIgnore]
510public bool zOrderSpecified
511{
512get
513{
514return this.zOrderFieldSpecified;
515}
516set
517{
518this.zOrderFieldSpecified = value;
519}
520}
521
522[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
523public ST_PageBorderDisplay display
524{
525get
526{
527return this.displayField;
528}
529set
530{
531this.displayField = value;
532}
533}
534
535[XmlIgnore]
536public bool displaySpecified
537{
538get
539{
540return this.displayFieldSpecified;
541}
542set
543{
544this.displayFieldSpecified = value;
545}
546}
547
548[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
549public ST_PageBorderOffset offsetFrom
550{
551get
552{
553return this.offsetFromField;
554}
555set
556{
557this.offsetFromField = value;
558}
559}
560
561[XmlIgnore]
562public bool offsetFromSpecified
563{
564get
565{
566return this.offsetFromFieldSpecified;
567}
568set
569{
570this.offsetFromFieldSpecified = value;
571}
572}
573}
574
575
576[Serializable]
577[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
578public enum ST_PageBorderZOrder
579{
580
581
582front,
583
584
585back,
586}
587
588
589[Serializable]
590[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
591public enum ST_PageBorderDisplay
592{
593
594
595allPages,
596
597
598firstPage,
599
600
601notFirstPage,
602}
603
604
605[Serializable]
606[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
607public enum ST_PageBorderOffset
608{
609
610
611page,
612
613
614text,
615}
616
617
618[Serializable]
619
620[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
621[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
622public class CT_PageNumber
623{
624
625private ST_NumberFormat fmtField;
626
627private bool fmtFieldSpecified;
628
629private string startField;
630
631private string chapStyleField;
632
633private ST_ChapterSep chapSepField;
634
635private bool chapSepFieldSpecified;
636public static CT_PageNumber Parse(XmlNode node, XmlNamespaceManager namespaceManager)
637{
638if (node == null)
639return null;
640CT_PageNumber ctObj = new CT_PageNumber();
641if (node.Attributes["w:fmt"] != null)
642ctObj.fmt = (ST_NumberFormat)Enum.Parse(typeof(ST_NumberFormat), node.Attributes["w:fmt"].Value);
643ctObj.start = XmlHelper.ReadString(node.Attributes["w:start"]);
644ctObj.chapStyle = XmlHelper.ReadString(node.Attributes["w:chapStyle"]);
645if (node.Attributes["w:chapSep"] != null)
646ctObj.chapSep = (ST_ChapterSep)Enum.Parse(typeof(ST_ChapterSep), node.Attributes["w:chapSep"].Value);
647return ctObj;
648}
649
650
651
652internal void Write(StreamWriter sw, string nodeName)
653{
654sw.Write(string.Format("<w:{0}", nodeName));
655XmlHelper.WriteAttribute(sw, "w:fmt", this.fmt.ToString());
656XmlHelper.WriteAttribute(sw, "w:start", this.start);
657XmlHelper.WriteAttribute(sw, "w:chapStyle", this.chapStyle);
658XmlHelper.WriteAttribute(sw, "w:chapSep", this.chapSep.ToString());
659sw.Write("/>");
660}
661
662[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
663public ST_NumberFormat fmt
664{
665get
666{
667return this.fmtField;
668}
669set
670{
671this.fmtField = value;
672}
673}
674
675[XmlIgnore]
676public bool fmtSpecified
677{
678get
679{
680return this.fmtFieldSpecified;
681}
682set
683{
684this.fmtFieldSpecified = value;
685}
686}
687
688[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
689public string start
690{
691get
692{
693return this.startField;
694}
695set
696{
697this.startField = value;
698}
699}
700
701[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
702public string chapStyle
703{
704get
705{
706return this.chapStyleField;
707}
708set
709{
710this.chapStyleField = value;
711}
712}
713
714[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
715public ST_ChapterSep chapSep
716{
717get
718{
719return this.chapSepField;
720}
721set
722{
723this.chapSepField = value;
724}
725}
726
727[XmlIgnore]
728public bool chapSepSpecified
729{
730get
731{
732return this.chapSepFieldSpecified;
733}
734set
735{
736this.chapSepFieldSpecified = value;
737}
738}
739}
740
741[Serializable]
742
743[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
744[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
745public class CT_SectType
746{
747
748private ST_SectionMark valField;
749
750private bool valFieldSpecified;
751public static CT_SectType Parse(XmlNode node, XmlNamespaceManager namespaceManager)
752{
753if (node == null)
754return null;
755CT_SectType ctObj = new CT_SectType();
756if (node.Attributes["w:val"] != null)
757ctObj.val = (ST_SectionMark)Enum.Parse(typeof(ST_SectionMark), node.Attributes["w:val"].Value);
758return ctObj;
759}
760
761
762
763internal void Write(StreamWriter sw, string nodeName)
764{
765sw.Write(string.Format("<w:{0}", nodeName));
766XmlHelper.WriteAttribute(sw, "w:val", this.val.ToString());
767sw.Write(">");
768sw.WriteEndW(nodeName);
769}
770
771[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
772public ST_SectionMark val
773{
774get
775{
776return this.valField;
777}
778set
779{
780this.valField = value;
781}
782}
783
784[XmlIgnore]
785public bool valSpecified
786{
787get
788{
789return this.valFieldSpecified;
790}
791set
792{
793this.valFieldSpecified = value;
794}
795}
796}
797
798
799[Serializable]
800[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
801public enum ST_SectionMark
802{
803
804
805nextPage,
806
807
808nextColumn,
809
810
811continuous,
812
813
814evenPage,
815
816
817oddPage,
818}
819[Serializable]
820
821[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
822[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
823public class CT_LineNumber
824{
825
826private string countByField;
827
828private string startField;
829
830private ulong distanceField;
831
832private bool distanceFieldSpecified;
833
834private ST_LineNumberRestart restartField;
835
836private bool restartFieldSpecified;
837public static CT_LineNumber Parse(XmlNode node, XmlNamespaceManager namespaceManager)
838{
839if (node == null)
840return null;
841CT_LineNumber ctObj = new CT_LineNumber();
842ctObj.countBy = XmlHelper.ReadString(node.Attributes["w:countBy"]);
843ctObj.start = XmlHelper.ReadString(node.Attributes["w:start"]);
844ctObj.distance = XmlHelper.ReadULong(node.Attributes["w:distance"]);
845if (node.Attributes["w:restart"] != null)
846ctObj.restart = (ST_LineNumberRestart)Enum.Parse(typeof(ST_LineNumberRestart), node.Attributes["w:restart"].Value);
847return ctObj;
848}
849
850
851
852internal void Write(StreamWriter sw, string nodeName)
853{
854sw.Write(string.Format("<w:{0}", nodeName));
855XmlHelper.WriteAttribute(sw, "w:countBy", this.countBy);
856XmlHelper.WriteAttribute(sw, "w:start", this.start);
857XmlHelper.WriteAttribute(sw, "w:distance", this.distance);
858XmlHelper.WriteAttribute(sw, "w:restart", this.restart.ToString());
859sw.Write(">");
860sw.WriteEndW(nodeName);
861}
862
863[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
864public string countBy
865{
866get
867{
868return this.countByField;
869}
870set
871{
872this.countByField = value;
873}
874}
875
876[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
877public string start
878{
879get
880{
881return this.startField;
882}
883set
884{
885this.startField = value;
886}
887}
888
889[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
890public ulong distance
891{
892get
893{
894return this.distanceField;
895}
896set
897{
898this.distanceField = value;
899}
900}
901
902[XmlIgnore]
903public bool distanceSpecified
904{
905get
906{
907return this.distanceFieldSpecified;
908}
909set
910{
911this.distanceFieldSpecified = value;
912}
913}
914
915[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
916public ST_LineNumberRestart restart
917{
918get
919{
920return this.restartField;
921}
922set
923{
924this.restartField = value;
925}
926}
927
928[XmlIgnore]
929public bool restartSpecified
930{
931get
932{
933return this.restartFieldSpecified;
934}
935set
936{
937this.restartFieldSpecified = value;
938}
939}
940}
941
942
943[Serializable]
944[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
945public enum ST_LineNumberRestart
946{
947
948
949newPage,
950
951
952newSection,
953
954
955continuous,
956}
957}
958