Пример #1
0
        public void TestSettings()
        {
            XWPFSettings settings = new XWPFSettings();

            settings.SetZoomPercent(50);
            Assert.AreEqual(50, settings.GetZoomPercent());
        }
Пример #2
0
 internal override void OnDocumentCreate()
 {
     this.ctDocument = new CT_Document();
     this.ctDocument.AddNewBody();
     this.Settings = (XWPFSettings)this.CreateRelationship((POIXMLRelation)XWPFRelation.SETTINGS, (POIXMLFactory)XWPFFactory.GetInstance());
     this.CreateStyles();
     this.GetProperties().GetExtendedProperties().GetUnderlyingProperties().Application = POIXMLDocument.DOCUMENT_CREATOR;
 }
Пример #3
0
 public void TestSettings()
 {
     XWPFSettings settings = new XWPFSettings();
     settings.SetZoomPercent(50);
     Assert.AreEqual(50, settings.GetZoomPercent());
 }
Пример #4
0
        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);
            }
            
        }
Пример #5
0
        /**
         * Create a new CT_Document with all values Set to default
         */

        internal override void OnDocumentCreate()
        {
            ctDocument = new CT_Document();
            ctDocument.AddNewBody();
            

            Settings = (XWPFSettings) CreateRelationship(XWPFRelation.SETTINGS,XWPFFactory.GetInstance());
            CreateStyles();

            ExtendedProperties expProps = GetProperties().ExtendedProperties;
            expProps.GetUnderlyingProperties().Application = (DOCUMENT_CREATOR);
        }
Пример #6
0
        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);
            }
            
        }
Пример #7
0
 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);
     }
 }