internal override void OnDocumentRead() { base.OnDocumentRead(); try { this.headerFooter = (CT_HdrFtr)HdrDocument.Parse(this.GetPackagePart().GetInputStream()).Hdr; foreach (object obj in this.headerFooter.Items) { if (obj is CT_P) { XWPFParagraph xwpfParagraph = new XWPFParagraph((CT_P)obj, (IBody)this); this.paragraphs.Add(xwpfParagraph); this.bodyElements.Add((IBodyElement)xwpfParagraph); } if (obj is CT_Tbl) { XWPFTable xwpfTable = new XWPFTable((CT_Tbl)obj, (IBody)this); this.tables.Add(xwpfTable); this.bodyElements.Add((IBodyElement)xwpfTable); } } } catch (Exception ex) { throw new POIXMLException(ex); } }
/// <summary> /// Read the document /// </summary> internal override void OnDocumentRead() { base.OnDocumentRead(); HdrDocument hdrDocument = null; try { XmlDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream()); hdrDocument = HdrDocument.Parse(xmldoc, NamespaceManager); headerFooter = hdrDocument.Hdr; foreach (object o in headerFooter.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } } } catch (Exception e) { throw new POIXMLException(e); } }
/** * save and Commit footer */ protected override void Commit() { /*XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); * xmlOptions.SaveSyntheticDocumentElement=(new QName(CTNumbering.type.Name.NamespaceURI, "hdr")); * Dictionary<String,String> map = new Dictionary<String, String>(); * map.Put("http://schemas.Openxmlformats.org/markup-compatibility/2006", "ve"); * map.Put("urn:schemas-microsoft-com:office:office", "o"); * map.Put("http://schemas.Openxmlformats.org/officeDocument/2006/relationships", "r"); * map.Put("http://schemas.Openxmlformats.org/officeDocument/2006/math", "m"); * map.Put("urn:schemas-microsoft-com:vml", "v"); * map.Put("http://schemas.Openxmlformats.org/drawingml/2006/wordProcessingDrawing", "wp"); * map.Put("urn:schemas-microsoft-com:office:word", "w10"); * map.Put("http://schemas.Openxmlformats.org/wordProcessingml/2006/main", "w"); * map.Put("http://schemas.microsoft.com/office/word/2006/wordml", "wne"); * xmlOptions.SaveSuggestedPrefixes=(/map);*/ PackagePart part = GetPackagePart(); Stream out1 = part.GetOutputStream(); HdrDocument doc = new HdrDocument((CT_Hdr)headerFooter); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[] { new XmlQualifiedName("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"), new XmlQualifiedName("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"), new XmlQualifiedName("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"), new XmlQualifiedName("v", "urn:schemas-microsoft-com:vml"), new XmlQualifiedName("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"), new XmlQualifiedName("w10", "urn:schemas-microsoft-com:office:word"), new XmlQualifiedName("wne", "http://schemas.microsoft.com/office/word/2006/wordml"), new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main") }); doc.Save(out1, namespaces); out1.Close(); }
protected override void Commit() { Stream outputStream = this.GetPackagePart().GetOutputStream(); HdrDocument hdrDocument = new HdrDocument((CT_Hdr)this.headerFooter); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(new XmlQualifiedName[8] { new XmlQualifiedName("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"), new XmlQualifiedName("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"), new XmlQualifiedName("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"), new XmlQualifiedName("v", "urn:schemas-microsoft-com:vml"), new XmlQualifiedName("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"), new XmlQualifiedName("w10", "urn:schemas-microsoft-com:office:word"), new XmlQualifiedName("wne", "http://schemas.microsoft.com/office/word/2006/wordml"), new XmlQualifiedName("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main") }); hdrDocument.Save(outputStream, namespaces); outputStream.Close(); }
/** * Reads the document * @throws IOException */ internal override void OnDocumentRead() { base.OnDocumentRead(); HdrDocument hdrDocument = null; Stream is1; try { is1 = GetPackagePart().GetInputStream(); hdrDocument = HdrDocument.Parse(is1); headerFooter = hdrDocument.Hdr; foreach (object o in headerFooter.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } } // parse the document with cursor and add // the XmlObject to its lists /*XmlCursor cursor = headerFooter.NewCursor(); * cursor.SelectPath("./*"); * while (cursor.ToNextSelection()) { * XmlObject o = cursor.Object; * if (o is CTP) { * XWPFParagraph p = new XWPFParagraph((CTP)o, this); * paragraphs.Add(p); * bodyElements.Add(p); * } * if (o is CTTbl) { * XWPFTable t = new XWPFTable((CTTbl)o, this); * tables.Add(t); * bodyElements.Add(t); * } * } * cursor.Dispose();*/ } catch (Exception e) { throw new POIXMLException(e); } }
/// <summary> /// Read the document /// </summary> internal override void OnDocumentRead() { base.OnDocumentRead(); HdrDocument hdrDocument = null; Stream is1 = null; try { is1 = GetPackagePart().GetInputStream(); XmlDocument xmldoc = DocumentHelper.LoadDocument(is1); hdrDocument = HdrDocument.Parse(xmldoc, NamespaceManager); headerFooter = hdrDocument.Hdr; foreach (object o in headerFooter.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); paragraphs.Add(p); bodyElements.Add(p); } if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); tables.Add(t); bodyElements.Add(t); } if (o is CT_SdtBlock) { XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); bodyElements.Add(c); } } } catch (Exception e) { throw new POIXMLException(e); } finally { if (is1 != null) { is1.Close(); } } }
public XWPFHeader CreateHeader(ST_HdrFtr type, XWPFParagraph[] pars) { XWPFRelation header = XWPFRelation.HEADER; string pStyle = "Header"; int relationIndex = this.GetRelationIndex(header); HdrDocument hdrDocument = new HdrDocument(); XWPFHeader relationship = (XWPFHeader)this.doc.CreateRelationship((POIXMLRelation)header, (POIXMLFactory)XWPFFactory.GetInstance(), relationIndex); CT_HdrFtr headerFooter = this.buildHdr(type, pStyle, (XWPFHeaderFooter)relationship, pars); relationship.SetHeaderFooter(headerFooter); Stream outputStream = relationship.GetPackagePart().GetOutputStream(); hdrDocument.SetHdr((CT_Hdr)headerFooter); this.assignHeader(relationship, type); hdrDocument.Save(outputStream, this.Commit((XWPFHeaderFooter)relationship)); outputStream.Close(); return(relationship); }
public XWPFHeader CreateHeader(ST_HdrFtr type, XWPFParagraph[] pars) { XWPFRelation relation = XWPFRelation.HEADER; String pStyle = "Header"; int i = GetRelationIndex(relation); HdrDocument hdrDoc = new HdrDocument(); XWPFHeader wrapper = (XWPFHeader)doc.CreateRelationship(relation, XWPFFactory.GetInstance(), i); CT_HdrFtr hdr = buildHdr(type, pStyle, wrapper, pars); wrapper.SetHeaderFooter(hdr); hdrDoc.SetHdr((CT_Hdr)hdr); assignHeader(wrapper, type); using (Stream outputStream = wrapper.GetPackagePart().GetOutputStream()) { hdrDoc.Save(outputStream); } return(wrapper); }