/** * Returns numbering format for this paragraph, eg bullet or * lowerLetter. * Returns null if this paragraph does not have numeric style. */ public String GetNumFmt() { string numID = GetNumID(); XWPFNumbering numbering = document.GetNumbering(); if (numID != null && numbering != null) { XWPFNum num = numbering.GetNum(numID); if (num != null) { string ilvl = GetNumIlvl(); string abstractNumId = num.GetCTNum().abstractNumId.val; CT_AbstractNum anum = numbering.GetAbstractNum(abstractNumId).GetAbstractNum(); CT_Lvl level = null; for (int i = 0; i < anum.lvl.Count; i++) { CT_Lvl lvl = anum.lvl[i]; if (lvl.ilvl.Equals(ilvl)) { level = lvl; break; } } if (level != null) { return(level.numFmt.val.ToString()); } } } return(null); }
public void TestOverrideList() { XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("NumberingWOverrides.docx"); XWPFParagraph p = doc.Paragraphs[(4)]; XWPFNumbering numbering = doc.GetNumbering(); CT_Num ctNum = numbering.GetNum(p.GetNumID()).GetCTNum(); Assert.AreEqual(9, ctNum.SizeOfLvlOverrideArray()); CT_NumLvl ctNumLvl = ctNum.GetLvlOverrideArray(0); Assert.AreEqual("upperLetter", ctNumLvl.lvl.numFmt.val.ToString()); }
public XWPFNumbering CreateNumbering() { if (this.numbering == null) { NumberingDocument numberingDocument = new NumberingDocument(); XWPFRelation numbering = XWPFRelation.NUMBERING; int relationIndex = this.GetRelationIndex(numbering); XWPFNumbering relationship = (XWPFNumbering)this.CreateRelationship((POIXMLRelation)numbering, (POIXMLFactory)XWPFFactory.GetInstance(), relationIndex); relationship.SetNumbering(numberingDocument.Numbering); this.numbering = relationship; } return(this.numbering); }
public void TestCompareAbstractNum() { XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("Numbering.docx"); XWPFNumbering numbering = doc.GetNumbering(); int numId = 1; Assert.IsTrue(numbering.NumExist(numId.ToString())); XWPFNum num = numbering.GetNum(numId.ToString()); string abstrNumId = num.GetCTNum().abstractNumId.val; XWPFAbstractNum abstractNum = numbering.GetAbstractNum(abstrNumId); string CompareAbstractNum = numbering.GetIdOfAbstractNum(abstractNum); Assert.AreEqual(abstrNumId, CompareAbstractNum); }
public void TestAddNumberingToDoc() { string abstractNumId = "1"; string numId = "1"; XWPFDocument docOut = new XWPFDocument(); XWPFNumbering numbering = docOut.CreateNumbering(); numId = numbering.AddNum(abstractNumId); XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut); numbering = docIn.GetNumbering(); Assert.IsTrue(numbering.NumExist(numId)); XWPFNum num = numbering.GetNum(numId); string CompareAbstractNum = num.GetCTNum().abstractNumId.val; Assert.AreEqual(abstractNumId, CompareAbstractNum); }
public void TestOverrideList() { //TODO: for now the try/catch block ensures loading/inclusion of CTNumLevel //for down stream Processing. //Ideally, we should find files that actually use overrides and test against those. //Use XWPFParagraph's GetNumStartOverride() in the actual tests XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("Numbering.docx"); XWPFParagraph p = doc.Paragraphs[(18)]; XWPFNumbering numbering = doc.CreateNumbering(); bool ex = false; Assert.IsNull(p.GetNumStartOverride()); try { numbering.GetNum(p.GetNumID()).GetCTNum().GetLvlOverrideArray(1); } catch (ArgumentOutOfRangeException e) { ex = true; } Assert.IsTrue(ex); }
public XWPFNum() { this.ctNum = null; this.numbering = null; }
internal override void OnDocumentRead() { try { XmlDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream()); DocumentDocument doc = DocumentDocument.Parse(xmldoc, NamespaceManager); ctDocument = doc.Document; InitFootnotes(); // parse the document with cursor and add // // the XmlObject to its lists foreach (object o in ctDocument.body.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); bodyElements.Add(p); paragraphs.Add(p); } else if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); bodyElements.Add(t); tables.Add(t); } else if (o is CT_SdtBlock) { XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this); bodyElements.Add(c); contentControls.Add(c); } } // Sort out headers and footers if (doc.Document.body.sectPr != null) headerFooterPolicy = new XWPFHeaderFooterPolicy(this); // Create for each XML-part in the Package a PartClass foreach (POIXMLDocumentPart p in GetRelations()) { String relation = p.GetPackageRelationship().RelationshipType; if (relation.Equals(XWPFRelation.STYLES.Relation)) { this.styles = (XWPFStyles)p; this.styles.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.NUMBERING.Relation)) { this.numbering = (XWPFNumbering)p; this.numbering.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.FOOTER.Relation)) { XWPFFooter footer = (XWPFFooter)p; footers.Add(footer); footer.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.HEADER.Relation)) { XWPFHeader header = (XWPFHeader)p; headers.Add(header); header.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.COMMENT.Relation)) { XmlDocument xml = ConvertStreamToXml(p.GetPackagePart().GetInputStream()); CommentsDocument cmntdoc = CommentsDocument.Parse(xml ,NamespaceManager); foreach (CT_Comment ctcomment in cmntdoc.Comments.comment) { comments.Add(new XWPFComment(ctcomment, this)); } } else if (relation.Equals(XWPFRelation.SETTINGS.Relation)) { Settings = (XWPFSettings)p; Settings.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.IMAGES.Relation)) { XWPFPictureData picData = (XWPFPictureData)p; picData.OnDocumentRead(); RegisterPackagePictureData(picData); pictures.Add(picData); } else if (relation.Equals(XWPFRelation.GLOSSARY_DOCUMENT.Relation)) { // We don't currently process the glossary itself // Until we do, we do need to load the glossary child parts of it foreach (POIXMLDocumentPart gp in p.GetRelations()) { // Trigger the onDocumentRead for all the child parts // Otherwise we'll hit issues on Styles, Settings etc on save try { gp.OnDocumentRead(); //Method onDocumentRead = gp.getClass().getDeclaredMethod("onDocumentRead"); //onDocumentRead.setAccessible(true); //onDocumentRead.invoke(gp); } catch (Exception e) { throw new POIXMLException(e); } } } } InitHyperlinks(); } catch (XmlException e) { throw new POIXMLException(e); } }
/** * Creates an empty numbering if one does not already exist and Sets the numbering member * @return numbering */ public XWPFNumbering CreateNumbering() { if(numbering == null) { NumberingDocument numberingDoc = new NumberingDocument(); XWPFRelation relation = XWPFRelation.NUMBERING; int i = GetRelationIndex(relation); XWPFNumbering wrapper = (XWPFNumbering)CreateRelationship(relation, XWPFFactory.GetInstance(), i); wrapper.SetNumbering(numberingDoc.Numbering); numbering = wrapper; } return numbering; }
/** * GetNumbering * @return numbering */ public XWPFNumbering GetNumbering() { if (numbering == null) numbering = new XWPFNumbering(); return numbering; }
public void SetNumbering(XWPFNumbering numbering) { this.numbering = numbering; }
public XWPFNum(CT_Num ctNum, XWPFNumbering numbering) { this.ctNum = ctNum; this.numbering = numbering; }
public XWPFAbstractNum(CT_AbstractNum ctAbstractNum, XWPFNumbering numbering) { this.ctAbstractNum = ctAbstractNum; this.numbering = numbering; }
protected XWPFAbstractNum() { this.ctAbstractNum = (CT_AbstractNum)null; this.numbering = (XWPFNumbering)null; }
public XWPFNum() { this.ctNum = (CT_Num)null; this.numbering = (XWPFNumbering)null; }
internal override void OnDocumentRead() { try { DocumentDocument doc = DocumentDocument.Parse(GetPackagePart().GetInputStream()); ctDocument = doc.Document; InitFootnotes(); foreach (object o in ctDocument.body.Items) { if (o is CT_P) { XWPFParagraph p = new XWPFParagraph((CT_P)o, this); bodyElements.Add(p); paragraphs.Add(p); } else if (o is CT_Tbl) { XWPFTable t = new XWPFTable((CT_Tbl)o, this); bodyElements.Add(t); tables.Add(t); } } // parse the document with cursor and add // // the XmlObject to its lists // XmlCursor cursor = ctDocument.Body.NewCursor(); // cursor.SelectPath("./*"); // while (cursor.ToNextSelection()) { // XmlObject o = cursor.Object; // if (o is CTP) { // XWPFParagraph p = new XWPFParagraph((CTP) o, this); // bodyElements.Add(p); // paragraphs.Add(p); // } else if (o is CTTbl) { // XWPFTable t = new XWPFTable((CTTbl) o, this); // bodyElements.Add(t); // tables.Add(t); // } // } // cursor.Dispose(); // Sort out headers and footers if (doc.Document.body.sectPr != null) headerFooterPolicy = new XWPFHeaderFooterPolicy(this); // Create for each XML-part in the Package a PartClass foreach (POIXMLDocumentPart p in GetRelations()) { String relation = p.GetPackageRelationship().RelationshipType; if (relation.Equals(XWPFRelation.STYLES.Relation)) { this.styles = (XWPFStyles)p; this.styles.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.NUMBERING.Relation)) { this.numbering = (XWPFNumbering)p; this.numbering.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.FOOTER.Relation)) { XWPFFooter footer = (XWPFFooter)p; footers.Add(footer); footer.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.HEADER.Relation)) { XWPFHeader header = (XWPFHeader)p; headers.Add(header); header.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.COMMENT.Relation)) { // TODO Create according XWPFComment class, extending POIXMLDocumentPart CommentsDocument cmntdoc = CommentsDocument.Parse(p.GetPackagePart().GetInputStream()); foreach (CT_Comment ctcomment in cmntdoc.Comments.comment) { comments.Add(new XWPFComment(ctcomment, this)); } } else if (relation.Equals(XWPFRelation.SETTINGS.Relation)) { Settings = (XWPFSettings)p; Settings.OnDocumentRead(); } else if (relation.Equals(XWPFRelation.IMAGES.Relation)) { XWPFPictureData picData = (XWPFPictureData)p; picData.OnDocumentRead(); RegisterPackagePictureData(picData); pictures.Add(picData); } } InitHyperlinks(); } catch (XmlException e) { throw new POIXMLException(e); } }
internal override void OnDocumentRead() { try { DocumentDocument documentDocument = DocumentDocument.Parse(this.GetPackagePart().GetInputStream()); this.ctDocument = documentDocument.Document; this.InitFootnotes(); foreach (object obj in this.ctDocument.body.Items) { if (obj is CT_P) { XWPFParagraph xwpfParagraph = new XWPFParagraph((CT_P)obj, (IBody)this); this.bodyElements.Add((IBodyElement)xwpfParagraph); this.paragraphs.Add(xwpfParagraph); } else if (obj is CT_Tbl) { XWPFTable xwpfTable = new XWPFTable((CT_Tbl)obj, (IBody)this); this.bodyElements.Add((IBodyElement)xwpfTable); this.tables.Add(xwpfTable); } } if (documentDocument.Document.body.sectPr != null) { this.headerFooterPolicy = new XWPFHeaderFooterPolicy(this); } foreach (POIXMLDocumentPart relation1 in this.GetRelations()) { string relationshipType = relation1.GetPackageRelationship().RelationshipType; if (relationshipType.Equals(XWPFRelation.STYLES.Relation)) { this.styles = (XWPFStyles)relation1; this.styles.OnDocumentRead(); } else if (relationshipType.Equals(XWPFRelation.NUMBERING.Relation)) { this.numbering = (XWPFNumbering)relation1; this.numbering.OnDocumentRead(); } else if (relationshipType.Equals(XWPFRelation.FOOTER.Relation)) { XWPFFooter xwpfFooter = (XWPFFooter)relation1; this.footers.Add(xwpfFooter); xwpfFooter.OnDocumentRead(); } else if (relationshipType.Equals(XWPFRelation.HEADER.Relation)) { XWPFHeader xwpfHeader = (XWPFHeader)relation1; this.headers.Add(xwpfHeader); xwpfHeader.OnDocumentRead(); } else if (relationshipType.Equals(XWPFRelation.COMMENT.Relation)) { foreach (CT_Comment comment in CommentsDocument.Parse(relation1.GetPackagePart().GetInputStream()).Comments.comment) { this.comments.Add(new XWPFComment(comment, this)); } } else if (relationshipType.Equals(XWPFRelation.SETTINGS.Relation)) { this.Settings = (XWPFSettings)relation1; this.Settings.OnDocumentRead(); } else if (relationshipType.Equals(XWPFRelation.IMAGES.Relation)) { XWPFPictureData picData = (XWPFPictureData)relation1; picData.OnDocumentRead(); this.RegisterPackagePictureData(picData); this.pictures.Add(picData); } else if (relationshipType.Equals(XWPFRelation.GLOSSARY_DOCUMENT.Relation)) { foreach (POIXMLDocumentPart relation2 in relation1.GetRelations()) { try { relation2.OnDocumentRead(); } catch (Exception ex) { throw new POIXMLException(ex); } } } } this.InitHyperlinks(); } catch (XmlException ex) { throw new POIXMLException((Exception)ex); } }
public XWPFNum(CT_Num ctNum) { this.ctNum = ctNum; this.numbering = null; }
public XWPFNum(XWPFNumbering numbering) { this.ctNum = null; this.numbering = numbering; }
protected XWPFAbstractNum() { this.ctAbstractNum = null; this.numbering = null; }