npoi
1512 строк · 46.0 Кб
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using System.Xml.Serialization;
5using NPOI.OpenXmlFormats.Shared;
6using NPOI.OpenXml4Net.Util;
7using System.IO;
8using System.Collections;
9using System.Linq;
10
11namespace NPOI.OpenXmlFormats.Wordprocessing
12{
13[Serializable]
14
15[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
16[XmlRoot("glossaryDocument", Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = false)]
17public class CT_GlossaryDocument : CT_DocumentBase
18{
19
20private CT_DocParts docPartsField;
21
22public CT_GlossaryDocument()
23{
24this.docPartsField = new CT_DocParts();
25}
26
27[XmlElement(Order = 0)]
28public CT_DocParts docParts
29{
30get
31{
32return this.docPartsField;
33}
34set
35{
36this.docPartsField = value;
37}
38}
39}
40[XmlInclude(typeof(CT_GlossaryDocument))]
41[XmlInclude(typeof(CT_Document))]
42[Serializable]
43[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
44[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
45public class CT_DocumentBase
46{
47
48private CT_Background backgroundField;
49
50public CT_DocumentBase()
51{
52//this.backgroundField = new CT_Background();
53}
54
55[XmlElement(Order = 0)]
56public CT_Background background
57{
58get
59{
60return this.backgroundField;
61}
62set
63{
64this.backgroundField = value;
65}
66}
67}
68
69
70[Serializable]
71
72[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
73[XmlRoot("document", Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = false)]
74public class CT_Document : CT_DocumentBase
75{
76public static CT_Document Parse(XmlNode node, XmlNamespaceManager namespaceManager)
77{
78if(node == null)
79return null;
80CT_Document ctObj = new CT_Document();
81foreach(XmlNode childNode in node.ChildNodes)
82{
83if(childNode.LocalName == "body")
84ctObj.body = CT_Body.Parse(childNode, namespaceManager);
85else if(childNode.LocalName == "background")
86ctObj.background = CT_Background.Parse(childNode, namespaceManager);
87}
88return ctObj;
89}
90
91
92
93internal void Write(StreamWriter sw)
94{
95sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
96sw.Write("<w:document xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" ");
97sw.Write("xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" ");
98sw.Write("xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:cx6=\"http://schemas.microsoft.com/office/drawing/2016/5/12/chartex\" ");
99sw.Write("xmlns:cx7=\"http://schemas.microsoft.com/office/drawing/2016/5/13/chartex\" xmlns:cx8=\"http://schemas.microsoft.com/office/drawing/2016/5/14/chartex\" ");
100sw.Write("xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" ");
101sw.Write("xmlns:aink=\"http://schemas.microsoft.com/office/drawing/2016/ink\" xmlns:am3d=\"http://schemas.microsoft.com/office/drawing/2017/model3d\" ");
102sw.Write("xmlns:o=\"urn:schemas-microsoft-com:office:office\" ");
103sw.Write("xmlns:oel=\"http://schemas.microsoft.com/office/2019/extlst\" ");
104sw.Write("xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" ");
105sw.Write("xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" ");
106sw.Write("xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" ");
107sw.Write("xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:w16cex=\"http://schemas.microsoft.com/office/word/2018/wordml/cex\" ");
108sw.Write("xmlns:w16cid=\"http://schemas.microsoft.com/office/word/2016/wordml/cid\" xmlns:w16=\"http://schemas.microsoft.com/office/word/2018/wordml\" xmlns:w16sdtdh=\"http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash\" ");
109sw.Write("xmlns:w16se=\"http://schemas.microsoft.com/office/word/2015/wordml/symex\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" ");
110sw.Write("xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" ");
111sw.Write("mc:Ignorable=\"w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14\">");
112if(this.body != null)
113this.body.Write(sw, "body");
114if(this.background != null)
115this.background.Write(sw, "background");
116sw.Write("</w:document>");
117}
118
119private CT_Body bodyField;
120
121public CT_Document()
122{
123this.bodyField = new CT_Body();
124}
125
126[XmlElement(Order = 0)]
127public CT_Body body
128{
129get
130{
131return this.bodyField;
132}
133set
134{
135this.bodyField = value;
136}
137}
138
139public void AddNewBody()
140{
141this.bodyField = new CT_Body();
142}
143}
144
145
146[Serializable]
147
148[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
149[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
150public class CT_Body
151{
152
153private ArrayList itemsField;
154
155private List<DocumentBodyItemChoiceType> itemsElementNameField;
156
157private CT_SectPr sectPrField;
158
159public CT_Body()
160{
161this.itemsElementNameField = new List<DocumentBodyItemChoiceType>();
162this.itemsField = new ArrayList();
163}
164public static CT_Body Parse(XmlNode node, XmlNamespaceManager namespaceManager)
165{
166if(node == null)
167return null;
168CT_Body ctObj = new CT_Body();
169foreach(XmlNode childNode in node.ChildNodes)
170{
171if(childNode.LocalName == "moveTo")
172{
173ctObj.Items.Add(CT_RunTrackChange.Parse(childNode, namespaceManager));
174ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveTo);
175}
176else if(childNode.LocalName == "sectPr")
177{
178ctObj.sectPr = CT_SectPr.Parse(childNode, namespaceManager);
179}
180else if(childNode.LocalName == "oMathPara")
181{
182ctObj.Items.Add(CT_OMathPara.Parse(childNode, namespaceManager));
183ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.oMathPara);
184}
185else if(childNode.LocalName == "customXml")
186{
187ctObj.Items.Add(CT_CustomXmlBlock.Parse(childNode, namespaceManager));
188ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXml);
189}
190else if(childNode.LocalName == "oMath")
191{
192ctObj.Items.Add(CT_OMath.Parse(childNode, namespaceManager));
193ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.oMath);
194}
195else if(childNode.LocalName == "altChunk")
196{
197ctObj.Items.Add(CT_AltChunk.Parse(childNode, namespaceManager));
198ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.altChunk);
199}
200else if(childNode.LocalName == "bookmarkEnd")
201{
202ctObj.Items.Add(CT_MarkupRange.Parse(childNode, namespaceManager));
203ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.bookmarkEnd);
204}
205else if(childNode.LocalName == "bookmarkStart")
206{
207ctObj.Items.Add(CT_Bookmark.Parse(childNode, namespaceManager));
208ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.bookmarkStart);
209}
210else if(childNode.LocalName == "commentRangeEnd")
211{
212ctObj.Items.Add(CT_MarkupRange.Parse(childNode, namespaceManager));
213ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.commentRangeEnd);
214}
215else if(childNode.LocalName == "commentRangeStart")
216{
217ctObj.Items.Add(CT_MarkupRange.Parse(childNode, namespaceManager));
218ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.commentRangeStart);
219}
220else if(childNode.LocalName == "customXmlDelRangeEnd")
221{
222ctObj.Items.Add(CT_Markup.Parse(childNode, namespaceManager));
223ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlDelRangeEnd);
224}
225else if(childNode.LocalName == "customXmlDelRangeStart")
226{
227ctObj.Items.Add(CT_TrackChange.Parse(childNode, namespaceManager));
228ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlDelRangeStart);
229}
230else if(childNode.LocalName == "customXmlInsRangeEnd")
231{
232ctObj.Items.Add(CT_Markup.Parse(childNode, namespaceManager));
233ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlInsRangeEnd);
234}
235else if(childNode.LocalName == "customXmlInsRangeStart")
236{
237ctObj.Items.Add(CT_TrackChange.Parse(childNode, namespaceManager));
238ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlInsRangeStart);
239}
240else if(childNode.LocalName == "customXmlMoveFromRangeEnd")
241{
242ctObj.Items.Add(CT_Markup.Parse(childNode, namespaceManager));
243ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlMoveFromRangeEnd);
244}
245else if(childNode.LocalName == "customXmlMoveFromRangeStart")
246{
247ctObj.Items.Add(CT_TrackChange.Parse(childNode, namespaceManager));
248ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlMoveFromRangeStart);
249}
250else if(childNode.LocalName == "customXmlMoveToRangeEnd")
251{
252ctObj.Items.Add(CT_Markup.Parse(childNode, namespaceManager));
253ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlMoveToRangeEnd);
254}
255else if(childNode.LocalName == "customXmlMoveToRangeStart")
256{
257ctObj.Items.Add(CT_TrackChange.Parse(childNode, namespaceManager));
258ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.customXmlMoveToRangeStart);
259}
260else if(childNode.LocalName == "del")
261{
262ctObj.Items.Add(CT_RunTrackChange.Parse(childNode, namespaceManager));
263ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.del);
264}
265else if(childNode.LocalName == "ins")
266{
267ctObj.Items.Add(CT_RunTrackChange.Parse(childNode, namespaceManager));
268ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.ins);
269}
270else if(childNode.LocalName == "moveFrom")
271{
272ctObj.Items.Add(CT_RunTrackChange.Parse(childNode, namespaceManager));
273ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveFrom);
274}
275else if(childNode.LocalName == "moveFromRangeEnd")
276{
277ctObj.Items.Add(CT_MarkupRange.Parse(childNode, namespaceManager));
278ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveFromRangeEnd);
279}
280else if(childNode.LocalName == "moveFromRangeStart")
281{
282ctObj.Items.Add(CT_MoveBookmark.Parse(childNode, namespaceManager));
283ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveFromRangeStart);
284}
285else if(childNode.LocalName == "moveToRangeEnd")
286{
287ctObj.Items.Add(CT_MarkupRange.Parse(childNode, namespaceManager));
288ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveToRangeEnd);
289}
290else if(childNode.LocalName == "moveToRangeStart")
291{
292ctObj.Items.Add(CT_MoveBookmark.Parse(childNode, namespaceManager));
293ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.moveToRangeStart);
294}
295else if(childNode.LocalName == "p")
296{
297ctObj.Items.Add(CT_P.Parse(childNode, namespaceManager));
298ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.p);
299}
300else if(childNode.LocalName == "permEnd")
301{
302ctObj.Items.Add(CT_Perm.Parse(childNode, namespaceManager));
303ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.permEnd);
304}
305else if(childNode.LocalName == "permStart")
306{
307ctObj.Items.Add(CT_PermStart.Parse(childNode, namespaceManager));
308ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.permStart);
309}
310else if(childNode.LocalName == "proofErr")
311{
312ctObj.Items.Add(CT_ProofErr.Parse(childNode, namespaceManager));
313ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.proofErr);
314}
315else if(childNode.LocalName == "sdt")
316{
317ctObj.Items.Add(CT_SdtBlock.Parse(childNode, namespaceManager));
318ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.sdt);
319}
320else if(childNode.LocalName == "tbl")
321{
322ctObj.Items.Add(CT_Tbl.Parse(childNode, namespaceManager));
323ctObj.ItemsElementName.Add(DocumentBodyItemChoiceType.tbl);
324}
325}
326return ctObj;
327}
328
329public int SizeOfPArray()
330{
331return this.itemsElementNameField.Count(p => p == DocumentBodyItemChoiceType.p);
332}
333
334internal void Write(StreamWriter sw, string nodeName)
335{
336sw.Write(string.Format("<w:{0}", nodeName));
337sw.Write(">");
338int i=0;
339foreach(object o in this.Items)
340{
341if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveTo)
342((CT_RunTrackChange) o).Write(sw, "moveTo");
343else if(o is CT_OMathPara)
344((CT_OMathPara) o).Write(sw, "oMathPara");
345else if(o is CT_CustomXmlBlock)
346((CT_CustomXmlBlock) o).Write(sw, "customXml");
347else if(o is CT_OMath)
348((CT_OMath) o).Write(sw, "oMath");
349else if(o is CT_AltChunk)
350((CT_AltChunk) o).Write(sw, "altChunk");
351else if((o is CT_MarkupRange)&&this.itemsElementNameField[i]== DocumentBodyItemChoiceType.bookmarkEnd)
352((CT_MarkupRange) o).Write(sw, "bookmarkEnd");
353else if(o is CT_Bookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.bookmarkStart)
354((CT_Bookmark) o).Write(sw, "bookmarkStart");
355else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeEnd)
356((CT_MarkupRange) o).Write(sw, "commentRangeEnd");
357else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.commentRangeStart)
358((CT_MarkupRange) o).Write(sw, "commentRangeStart");
359else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeEnd)
360((CT_Markup) o).Write(sw, "customXmlDelRangeEnd");
361else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlDelRangeStart)
362((CT_TrackChange) o).Write(sw, "customXmlDelRangeStart");
363else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeEnd)
364((CT_Markup) o).Write(sw, "customXmlInsRangeEnd");
365else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlInsRangeStart)
366((CT_TrackChange) o).Write(sw, "customXmlInsRangeStart");
367else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeEnd)
368((CT_Markup) o).Write(sw, "customXmlMoveFromRangeEnd");
369else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveFromRangeStart)
370((CT_TrackChange) o).Write(sw, "customXmlMoveFromRangeStart");
371else if(o is CT_Markup && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeEnd)
372((CT_Markup) o).Write(sw, "customXmlMoveToRangeEnd");
373else if(o is CT_TrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.customXmlMoveToRangeStart)
374((CT_TrackChange) o).Write(sw, "customXmlMoveToRangeStart");
375else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.del)
376((CT_RunTrackChange) o).Write(sw, "del");
377else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.ins)
378((CT_RunTrackChange) o).Write(sw, "ins");
379else if(o is CT_RunTrackChange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFrom)
380((CT_RunTrackChange) o).Write(sw, "moveFrom");
381else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeEnd)
382((CT_MarkupRange) o).Write(sw, "moveFromRangeEnd");
383else if(o is CT_MoveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveFromRangeStart)
384((CT_MoveBookmark) o).Write(sw, "moveFromRangeStart");
385else if(o is CT_MarkupRange && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeEnd)
386((CT_MarkupRange) o).Write(sw, "moveToRangeEnd");
387else if(o is CT_MoveBookmark && this.itemsElementNameField[i] == DocumentBodyItemChoiceType.moveToRangeStart)
388((CT_MoveBookmark) o).Write(sw, "moveToRangeStart");
389else if(o is CT_P)
390((CT_P) o).Write(sw, "p");
391else if(o is CT_Perm)
392((CT_Perm) o).Write(sw, "permEnd");
393else if(o is CT_PermStart)
394((CT_PermStart) o).Write(sw, "permStart");
395else if(o is CT_ProofErr)
396((CT_ProofErr) o).Write(sw, "proofErr");
397else if(o is CT_SdtBlock)
398((CT_SdtBlock) o).Write(sw, "sdt");
399else if(o is CT_Tbl)
400((CT_Tbl) o).Write(sw, "tbl");
401i++;
402}
403if(this.sectPr != null)
404this.sectPr.Write(sw, "sectPr");
405sw.WriteEndW(nodeName);
406}
407
408public CT_SectPr AddNewSectPr()
409{
410this.sectPrField = new CT_SectPr();
411return this.sectPrField;
412}
413
414public bool IsSetSectPr()
415{
416return this.sectPrField != null;
417}
418
419[XmlElement("oMath", typeof(CT_OMath), Namespace = "http://schemas.openxmlformats.org/officeDocument/2006/math", Order = 0)]
420[XmlElement("oMathPara", typeof(CT_OMathPara), Namespace = "http://schemas.openxmlformats.org/officeDocument/2006/math", Order = 0)]
421[XmlElement("altChunk", typeof(CT_AltChunk), Order = 0)]
422[XmlElement("bookmarkEnd", typeof(CT_MarkupRange), Order = 0)]
423[XmlElement("bookmarkStart", typeof(CT_Bookmark), Order = 0)]
424[XmlElement("commentRangeEnd", typeof(CT_MarkupRange), Order = 0)]
425[XmlElement("commentRangeStart", typeof(CT_MarkupRange), Order = 0)]
426[XmlElement("customXml", typeof(CT_CustomXmlBlock), Order = 0)]
427[XmlElement("customXmlDelRangeEnd", typeof(CT_Markup), Order = 0)]
428[XmlElement("customXmlDelRangeStart", typeof(CT_TrackChange), Order = 0)]
429[XmlElement("customXmlInsRangeEnd", typeof(CT_Markup), Order = 0)]
430[XmlElement("customXmlInsRangeStart", typeof(CT_TrackChange), Order = 0)]
431[XmlElement("customXmlMoveFromRangeEnd", typeof(CT_Markup), Order = 0)]
432[XmlElement("customXmlMoveFromRangeStart", typeof(CT_TrackChange), Order = 0)]
433[XmlElement("customXmlMoveToRangeEnd", typeof(CT_Markup), Order = 0)]
434[XmlElement("customXmlMoveToRangeStart", typeof(CT_TrackChange), Order = 0)]
435[XmlElement("del", Type = typeof(CT_RunTrackChange), Order = 0)]
436[XmlElement("ins", Type = typeof(CT_RunTrackChange), Order = 0)]
437[XmlElement("moveFrom", typeof(CT_RunTrackChange), Order = 0)]
438[XmlElement("moveFromRangeEnd", typeof(CT_MarkupRange), Order = 0)]
439[XmlElement("moveFromRangeStart", typeof(CT_MoveBookmark), Order = 0)]
440[XmlElement("moveTo", typeof(CT_RunTrackChange), Order = 0)]
441[XmlElement("moveToRangeEnd", typeof(CT_MarkupRange), Order = 0)]
442[XmlElement("moveToRangeStart", typeof(CT_MoveBookmark), Order = 0)]
443[XmlElement("p", typeof(CT_P), Order = 0)]
444[XmlElement("permEnd", typeof(CT_Perm), Order = 0)]
445[XmlElement("permStart", typeof(CT_PermStart), Order = 0)]
446[XmlElement("proofErr", typeof(CT_ProofErr), Order = 0)]
447[XmlElement("sdt", typeof(CT_SdtBlock), Order = 0)]
448[XmlElement("tbl", typeof(CT_Tbl), Order = 0)]
449[XmlChoiceIdentifier("ItemsElementName")]
450public ArrayList Items
451{
452get
453{
454return this.itemsField;
455}
456set
457{
458this.itemsField = value;
459}
460}
461
462public CT_P AddNewP()
463{
464CT_P p = new CT_P();
465lock(this)
466{
467this.itemsField.Add(p);
468this.itemsElementNameField.Add(DocumentBodyItemChoiceType.p);
469}
470return p;
471}
472
473[XmlElement("ItemsElementName", Order = 1)]
474[XmlIgnore]
475public List<DocumentBodyItemChoiceType> ItemsElementName
476{
477get
478{
479return this.itemsElementNameField;
480}
481set
482{
483this.itemsElementNameField = value;
484}
485}
486
487[XmlElement(Order = 2)]
488public CT_SectPr sectPr
489{
490get
491{
492return this.sectPrField;
493}
494set
495{
496this.sectPrField = value;
497}
498}
499public CT_Tbl AddNewTbl(int? pos = null)
500{
501CT_Tbl tbl = new CT_Tbl();
502lock(this)
503{
504if(pos.HasValue)
505{
506this.itemsField.Insert(pos.Value, tbl);
507this.itemsElementNameField.Insert(pos.Value, DocumentBodyItemChoiceType.tbl);
508}
509else
510{
511this.itemsField.Add(tbl);
512this.itemsElementNameField.Add(DocumentBodyItemChoiceType.tbl);
513}
514}
515return tbl;
516}
517public int sizeOfTblArray()
518{
519return SizeOfArray(DocumentBodyItemChoiceType.tbl);
520}
521public List<CT_Tbl> getTblArray()
522{
523return GetObjectList<CT_Tbl>(DocumentBodyItemChoiceType.tbl);
524}
525public CT_Tbl insertNewTbl(int paramInt)
526{
527throw new NotImplementedException();
528}
529public void removeTbl(int paramInt)
530{
531throw new NotImplementedException();
532}
533public CT_Tbl GetTblArray(int i)
534{
535return GetObjectArray<CT_Tbl>(i, DocumentBodyItemChoiceType.tbl);
536}
537
538public void SetTblArray(int pos, CT_Tbl cT_Tbl)
539{
540SetObject<CT_Tbl>(DocumentBodyItemChoiceType.tbl, pos, cT_Tbl);
541}
542
543public CT_Tbl[] GetTblArray()
544{
545return GetObjectList<CT_Tbl>(DocumentBodyItemChoiceType.tbl).ToArray();
546}
547
548public CT_P GetPArray(int p)
549{
550return GetObjectArray<CT_P>(p, DocumentBodyItemChoiceType.p);
551}
552public void RemoveP(int paraPos)
553{
554RemoveObject(DocumentBodyItemChoiceType.p, paraPos);
555}
556public void RemoveTbl(int tablePos)
557{
558RemoveObject(DocumentBodyItemChoiceType.tbl, tablePos);
559}
560
561public CT_SdtBlock AddNewSdt()
562{
563return AddNewObject<CT_SdtBlock>(DocumentBodyItemChoiceType.sdt);
564}
565#region Generic methods for object operation
566
567private List<T> GetObjectList<T>(DocumentBodyItemChoiceType type) where T : class
568{
569lock(this)
570{
571List<T> list = new List<T>();
572for(int i = 0; i < itemsElementNameField.Count; i++)
573{
574if(itemsElementNameField[i] == type)
575list.Add(itemsField[i] as T);
576}
577return list;
578}
579}
580private int SizeOfArray(DocumentBodyItemChoiceType type)
581{
582lock(this)
583{
584int size = 0;
585for(int i = 0; i < itemsElementNameField.Count; i++)
586{
587if(itemsElementNameField[i] == type)
588size++;
589}
590return size;
591}
592}
593private T GetObjectArray<T>(int p, DocumentBodyItemChoiceType type) where T : class
594{
595lock(this)
596{
597int pos = GetObjectIndex(type, p);
598if(pos < 0 || pos >= this.itemsField.Count)
599return null;
600return itemsField[pos] as T;
601}
602}
603private T AddNewObject<T>(DocumentBodyItemChoiceType type) where T : class, new()
604{
605T t = new T();
606lock(this)
607{
608this.itemsElementNameField.Add(type);
609this.itemsField.Add(t);
610}
611return t;
612}
613private void SetObject<T>(DocumentBodyItemChoiceType type, int p, T obj) where T : class
614{
615lock(this)
616{
617int pos = GetObjectIndex(type, p);
618if(pos < 0 || pos >= this.itemsField.Count)
619return;
620if(this.itemsField[pos] is T)
621this.itemsField[pos] = obj;
622else
623throw new Exception(string.Format(@"object types are difference, itemsField[{0}] is {1}, and parameter obj is {2}",
624pos, this.itemsField[pos].GetType().Name, typeof(T).Name));
625}
626}
627private int GetObjectIndex(DocumentBodyItemChoiceType type, int p)
628{
629int index = -1;
630int pos = 0;
631for(int i = 0; i < itemsElementNameField.Count; i++)
632{
633if(itemsElementNameField[i] == type)
634{
635if(pos == p)
636{
637index = i;
638break;
639}
640else
641pos++;
642}
643}
644return index;
645}
646private void RemoveObject(DocumentBodyItemChoiceType type, int p)
647{
648lock(this)
649{
650int pos = GetObjectIndex(type, p);
651if(pos < 0 || pos >= this.itemsField.Count)
652return;
653itemsElementNameField.RemoveAt(pos);
654itemsField.RemoveAt(pos);
655}
656}
657#endregion
658
659
660
661
662public void SetPArray(int pos, CT_P cT_P)
663{
664SetObject<CT_P>(DocumentBodyItemChoiceType.p, pos, cT_P);
665}
666}
667
668
669[Serializable]
670[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IncludeInSchema = false)]
671public enum DocumentBodyItemChoiceType
672{
673
674
675[XmlEnum("http://schemas.openxmlformats.org/officeDocument/2006/math:oMath")]
676oMath,
677
678
679[XmlEnum("http://schemas.openxmlformats.org/officeDocument/2006/math:oMathPara")]
680oMathPara,
681
682
683altChunk,
684
685
686bookmarkEnd,
687
688
689bookmarkStart,
690
691
692commentRangeEnd,
693
694
695commentRangeStart,
696
697
698customXml,
699
700
701customXmlDelRangeEnd,
702
703
704customXmlDelRangeStart,
705
706
707customXmlInsRangeEnd,
708
709
710customXmlInsRangeStart,
711
712
713customXmlMoveFromRangeEnd,
714
715
716customXmlMoveFromRangeStart,
717
718
719customXmlMoveToRangeEnd,
720
721
722customXmlMoveToRangeStart,
723
724
725del,
726
727
728ins,
729
730
731moveFrom,
732
733
734moveFromRangeEnd,
735
736
737moveFromRangeStart,
738
739
740moveTo,
741
742
743moveToRangeEnd,
744
745
746moveToRangeStart,
747
748/// <summary>
749/// Paragraph
750/// </summary>
751p,
752
753
754permEnd,
755
756
757permStart,
758
759
760proofErr,
761
762
763sdt,
764
765
766tbl,
767}
768
769
770[Serializable]
771
772[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
773[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
774public class CT_DocParts
775{
776
777private List<CT_DocPart> itemsField;
778
779public CT_DocParts()
780{
781this.itemsField = new List<CT_DocPart>();
782}
783
784[XmlElement("docPart", Order = 0)]
785public List<CT_DocPart> Items
786{
787get
788{
789return this.itemsField;
790}
791set
792{
793this.itemsField = value;
794}
795}
796}
797
798
799[Serializable]
800
801[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
802[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
803public class CT_DocPart
804{
805
806private CT_DocPartPr docPartPrField;
807
808private CT_Body docPartBodyField;
809
810public CT_DocPart()
811{
812//this.docPartBodyField = new CT_Body();
813//this.docPartPrField = new CT_DocPartPr();
814}
815
816[XmlElement(Order = 0)]
817public CT_DocPartPr docPartPr
818{
819get
820{
821return this.docPartPrField;
822}
823set
824{
825this.docPartPrField = value;
826}
827}
828
829[XmlElement(Order = 1)]
830public CT_Body docPartBody
831{
832get
833{
834return this.docPartBodyField;
835}
836set
837{
838this.docPartBodyField = value;
839}
840}
841}
842
843
844[Serializable]
845
846[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
847[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
848public class CT_DocPartPr
849{
850
851private object[] itemsField;
852
853private ItemsChoiceType11[] itemsElementNameField;
854
855public CT_DocPartPr()
856{
857this.itemsElementNameField = new ItemsChoiceType11[0];
858this.itemsField = new object[0];
859}
860
861[XmlElement("behaviors", typeof(CT_DocPartBehaviors), Order = 0)]
862[XmlElement("category", typeof(CT_DocPartCategory), Order = 0)]
863[XmlElement("description", typeof(CT_String), Order = 0)]
864[XmlElement("guid", typeof(CT_Guid), Order = 0)]
865[XmlElement("name", typeof(CT_DocPartName), Order = 0)]
866[XmlElement("style", typeof(CT_String), Order = 0)]
867[XmlElement("types", typeof(CT_DocPartTypes), Order = 0)]
868[XmlChoiceIdentifier("ItemsElementName")]
869public object[] Items
870{
871get
872{
873return this.itemsField;
874}
875set
876{
877this.itemsField = value;
878}
879}
880
881[XmlElement("ItemsElementName", Order = 1)]
882[XmlIgnore]
883public ItemsChoiceType11[] ItemsElementName
884{
885get
886{
887return this.itemsElementNameField;
888}
889set
890{
891this.itemsElementNameField = value;
892}
893}
894}
895
896
897[Serializable]
898
899[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
900[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
901public class CT_DocPartBehaviors
902{
903
904private List<CT_DocPartBehavior> itemsField;
905
906public CT_DocPartBehaviors()
907{
908this.itemsField = new List<CT_DocPartBehavior>();
909}
910
911[XmlElement("behavior", Order = 0)]
912public List<CT_DocPartBehavior> Items
913{
914get
915{
916return this.itemsField;
917}
918set
919{
920this.itemsField = value;
921}
922}
923}
924
925
926[Serializable]
927
928[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
929[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
930public class CT_DocPartBehavior
931{
932
933private ST_DocPartBehavior valField;
934
935[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
936public ST_DocPartBehavior val
937{
938get
939{
940return this.valField;
941}
942set
943{
944this.valField = value;
945}
946}
947}
948
949
950[Serializable]
951[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
952public enum ST_DocPartBehavior
953{
954
955
956content,
957
958
959p,
960
961
962pg,
963}
964
965
966[Serializable]
967
968[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
969[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
970public class CT_DocPartCategory
971{
972
973private CT_String nameField;
974
975private CT_DocPartGallery galleryField;
976
977public CT_DocPartCategory()
978{
979this.galleryField = new CT_DocPartGallery();
980this.nameField = new CT_String();
981}
982
983[XmlElement(Order = 0)]
984public CT_String name
985{
986get
987{
988return this.nameField;
989}
990set
991{
992this.nameField = value;
993}
994}
995
996[XmlElement(Order = 1)]
997public CT_DocPartGallery gallery
998{
999get
1000{
1001return this.galleryField;
1002}
1003set
1004{
1005this.galleryField = value;
1006}
1007}
1008}
1009
1010
1011[Serializable]
1012[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1013[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1014public class CT_DocPartGallery
1015{
1016
1017private ST_DocPartGallery valField;
1018
1019[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1020public ST_DocPartGallery val
1021{
1022get
1023{
1024return this.valField;
1025}
1026set
1027{
1028this.valField = value;
1029}
1030}
1031}
1032
1033
1034[Serializable]
1035[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1036public enum ST_DocPartGallery
1037{
1038
1039
1040placeholder,
1041
1042
1043any,
1044
1045
1046@default,
1047
1048
1049docParts,
1050
1051
1052coverPg,
1053
1054
1055eq,
1056
1057
1058ftrs,
1059
1060
1061hdrs,
1062
1063
1064pgNum,
1065
1066
1067tbls,
1068
1069
1070watermarks,
1071
1072
1073autoTxt,
1074
1075
1076txtBox,
1077
1078
1079pgNumT,
1080
1081
1082pgNumB,
1083
1084
1085pgNumMargins,
1086
1087
1088tblOfContents,
1089
1090
1091bib,
1092
1093
1094custQuickParts,
1095
1096
1097custCoverPg,
1098
1099
1100custEq,
1101
1102
1103custFtrs,
1104
1105
1106custHdrs,
1107
1108
1109custPgNum,
1110
1111
1112custTbls,
1113
1114
1115custWatermarks,
1116
1117
1118custAutoTxt,
1119
1120
1121custTxtBox,
1122
1123
1124custPgNumT,
1125
1126
1127custPgNumB,
1128
1129
1130custPgNumMargins,
1131
1132
1133custTblOfContents,
1134
1135
1136custBib,
1137
1138
1139custom1,
1140
1141
1142custom2,
1143
1144
1145custom3,
1146
1147
1148custom4,
1149
1150
1151custom5,
1152}
1153
1154[Serializable]
1155[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1156[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1157public class CT_DocPartName
1158{
1159
1160private string valField;
1161
1162private ST_OnOff decoratedField;
1163
1164private bool decoratedFieldSpecified;
1165
1166[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1167public string val
1168{
1169get
1170{
1171return this.valField;
1172}
1173set
1174{
1175this.valField = value;
1176}
1177}
1178
1179[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1180public ST_OnOff decorated
1181{
1182get
1183{
1184return this.decoratedField;
1185}
1186set
1187{
1188this.decoratedField = value;
1189}
1190}
1191
1192[XmlIgnore]
1193public bool decoratedSpecified
1194{
1195get
1196{
1197return this.decoratedFieldSpecified;
1198}
1199set
1200{
1201this.decoratedFieldSpecified = value;
1202}
1203}
1204}
1205
1206
1207[Serializable]
1208[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1209[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1210public class CT_DocPartTypes
1211{
1212
1213private List<CT_DocPartType> itemsField;
1214
1215private ST_OnOff allField;
1216
1217private bool allFieldSpecified;
1218
1219public CT_DocPartTypes()
1220{
1221this.itemsField = new List<CT_DocPartType>();
1222}
1223
1224[XmlElement("type", Order = 0)]
1225public List<CT_DocPartType> Items
1226{
1227get
1228{
1229return this.itemsField;
1230}
1231set
1232{
1233this.itemsField = value;
1234}
1235}
1236
1237[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1238public ST_OnOff all
1239{
1240get
1241{
1242return this.allField;
1243}
1244set
1245{
1246this.allField = value;
1247}
1248}
1249
1250[XmlIgnore]
1251public bool allSpecified
1252{
1253get
1254{
1255return this.allFieldSpecified;
1256}
1257set
1258{
1259this.allFieldSpecified = value;
1260}
1261}
1262}
1263
1264
1265[Serializable]
1266[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1267[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1268public class CT_DocPartType
1269{
1270
1271private ST_DocPartType valField;
1272
1273[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1274public ST_DocPartType val
1275{
1276get
1277{
1278return this.valField;
1279}
1280set
1281{
1282this.valField = value;
1283}
1284}
1285}
1286
1287
1288[Serializable]
1289[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1290public enum ST_DocPartType
1291{
1292
1293
1294none,
1295
1296
1297normal,
1298
1299
1300autoExp,
1301
1302
1303toolbar,
1304
1305
1306speller,
1307
1308
1309formFld,
1310
1311
1312bbPlcHdr,
1313}
1314
1315[Serializable]
1316[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IncludeInSchema = false)]
1317public enum ItemsChoiceType11
1318{
1319
1320
1321behaviors,
1322
1323
1324category,
1325
1326
1327description,
1328
1329
1330guid,
1331
1332
1333name,
1334
1335
1336style,
1337
1338
1339types,
1340}
1341
1342[Serializable]
1343
1344[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1345[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1346public class CT_DocGrid
1347{
1348
1349private ST_DocGrid typeField;
1350
1351private bool typeFieldSpecified;
1352
1353private string linePitchField;
1354
1355private string charSpaceField;
1356public CT_DocGrid()
1357{
1358this.type = ST_DocGrid.@default;
1359}
1360
1361public static CT_DocGrid Parse(XmlNode node, XmlNamespaceManager namespaceManager)
1362{
1363if(node == null)
1364return null;
1365CT_DocGrid ctObj = new CT_DocGrid();
1366if(node.Attributes["w:type"] != null)
1367ctObj.type = (ST_DocGrid) Enum.Parse(typeof(ST_DocGrid), node.Attributes["w:type"].Value);
1368ctObj.linePitch = XmlHelper.ReadString(node.Attributes["w:linePitch"]);
1369ctObj.charSpace = XmlHelper.ReadString(node.Attributes["w:charSpace"]);
1370return ctObj;
1371}
1372
1373
1374
1375internal void Write(StreamWriter sw, string nodeName)
1376{
1377sw.Write(string.Format("<w:{0}", nodeName));
1378if(this.type!= ST_DocGrid.@default)
1379XmlHelper.WriteAttribute(sw, "w:type", this.type.ToString());
1380XmlHelper.WriteAttribute(sw, "w:linePitch", this.linePitch);
1381XmlHelper.WriteAttribute(sw, "w:charSpace", this.charSpace);
1382sw.Write("/>");
1383}
1384
1385[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
1386public ST_DocGrid type
1387{
1388get
1389{
1390return this.typeField;
1391}
1392set
1393{
1394this.typeField = value;
1395}
1396}
1397
1398[XmlIgnore]
1399public bool typeSpecified
1400{
1401get
1402{
1403return this.typeFieldSpecified;
1404}
1405set
1406{
1407this.typeFieldSpecified = value;
1408}
1409}
1410
1411[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
1412public string linePitch
1413{
1414get
1415{
1416return this.linePitchField;
1417}
1418set
1419{
1420this.linePitchField = value;
1421}
1422}
1423
1424[XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, DataType = "integer")]
1425public string charSpace
1426{
1427get
1428{
1429return this.charSpaceField;
1430}
1431set
1432{
1433this.charSpaceField = value;
1434}
1435}
1436}
1437
1438
1439[Serializable]
1440[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1441public enum ST_DocGrid
1442{
1443
1444
1445@default,
1446
1447
1448lines,
1449
1450
1451linesAndChars,
1452
1453
1454snapToChars,
1455}
1456
1457[Serializable]
1458
1459[XmlType(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main")]
1460[XmlRoot(Namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", IsNullable = true)]
1461public class CT_DocVars
1462{
1463
1464private List<CT_DocVar> docVarField;
1465
1466public CT_DocVars()
1467{
1468this.docVarField = new List<CT_DocVar>();
1469}
1470
1471[XmlElement("docVar", Order = 0)]
1472public List<CT_DocVar> docVar
1473{
1474get
1475{
1476return this.docVarField;
1477}
1478set
1479{
1480this.docVarField = value;
1481}
1482}
1483
1484public static CT_DocVars Parse(XmlNode node, XmlNamespaceManager namespaceManager)
1485{
1486if(node == null)
1487return null;
1488
1489CT_DocVars ctObj = new CT_DocVars();
1490ctObj.docVar = new List<CT_DocVar>();
1491foreach(XmlNode childNode in node.ChildNodes)
1492ctObj.docVar.Add(CT_DocVar.Parse(childNode, namespaceManager));
1493
1494return ctObj;
1495}
1496
1497internal void Write(StreamWriter sw, string nodeName)
1498{
1499sw.Write(string.Format("<w:{0}", nodeName));
1500sw.Write(">");
1501if(this.docVar != null)
1502{
1503foreach(CT_DocVar x in this.docVar)
1504{
1505x.Write(sw, "docVar");
1506}
1507}
1508sw.WriteEndW(nodeName);
1509}
1510}
1511
1512}
1513