コード例 #1
0
ファイル: XWPFStyle.cs プロジェクト: ruo2012/Npoi.Core
        /**
         * Compares the names of the Styles
         * @param compStyle
         */

        public bool HasSameName(XWPFStyle compStyle)
        {
            CT_Style ctCompStyle = compStyle.GetCTStyle();
            String   name        = ctCompStyle.name.val;

            return(name.Equals(ctStyle.name.val));
        }
コード例 #2
0
        /**
         * Get the styles which are related to parameter style
         * @param style
         * @return all Styles of the parameterList
         */

        private List <XWPFStyle> GetUsedStyleList(XWPFStyle style, List <XWPFStyle> usedStyleList)
        {
            String    basisStyleID = style.BasisStyleID;
            XWPFStyle basisStyle   = GetStyle(basisStyleID);

            if ((basisStyle != null) && (!usedStyleList.Contains(basisStyle)))
            {
                usedStyleList.Add(basisStyle);
                GetUsedStyleList(basisStyle, usedStyleList);
            }
            String    linkStyleID = style.LinkStyleID;
            XWPFStyle linkStyle   = GetStyle(linkStyleID);

            if ((linkStyle != null) && (!usedStyleList.Contains(linkStyle)))
            {
                usedStyleList.Add(linkStyle);
                GetUsedStyleList(linkStyle, usedStyleList);
            }

            String    nextStyleID = style.NextStyleID;
            XWPFStyle nextStyle   = GetStyle(nextStyleID);

            if ((nextStyle != null) && (!usedStyleList.Contains(nextStyle)))
            {
                usedStyleList.Add(linkStyle);
                GetUsedStyleList(linkStyle, usedStyleList);
            }
            return(usedStyleList);
        }
コード例 #3
0
        /**
         * Get the styles which are related to the parameter style and their relatives
         * this method can be used to copy all styles from one document to another document
         * @param style
         * @return a list of all styles which were used by this method
         */

        public List <XWPFStyle> GetUsedStyleList(XWPFStyle style)
        {
            List <XWPFStyle> usedStyleList = new List <XWPFStyle>();

            usedStyleList.Add(style);
            return(GetUsedStyleList(style, usedStyleList));
        }
コード例 #4
0
        public void TestType()
        {
            CT_Style  ctStyle = new CT_Style();
            XWPFStyle style   = new XWPFStyle(ctStyle);

            style.StyleType = ST_StyleType.paragraph;
            Assert.AreEqual(ST_StyleType.paragraph, style.StyleType);
        }
コード例 #5
0
        /**
         * add a style to the document
         * @param style
         * @throws IOException
         */

        public void AddStyle(XWPFStyle style)
        {
            listStyle.Add(style);
            ctStyles.AddNewStyle();
            int pos = (ctStyles.GetStyleList().Count) - 1;

            ctStyles.SetStyleArray(pos, style.GetCTStyle());
        }
コード例 #6
0
        /**
         * Get the style with the same name
         * if this style is not existing, return null
         */

        public XWPFStyle GetStyleWithSameName(XWPFStyle style)
        {
            foreach (XWPFStyle ownStyle in listStyle)
            {
                if (ownStyle.HasSameName(style))
                {
                    return(ownStyle);
                }
            }
            return(null);
        }
コード例 #7
0
        public void TestAddStylesToDocument()
        {
            XWPFDocument docOut = new XWPFDocument();
            XWPFStyles   styles = docOut.CreateStyles();

            String   strStyleId = "headline1";
            CT_Style ctStyle    = new CT_Style();

            ctStyle.styleId = (strStyleId);
            XWPFStyle s = new XWPFStyle(ctStyle);

            styles.AddStyle(s);

            Assert.IsTrue(styles.StyleExist(strStyleId));

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            styles = docIn.GetStyles();
            Assert.IsTrue(styles.StyleExist(strStyleId));
        }
コード例 #8
0
        public void TestGetUsedStyles()
        {
            XWPFDocument     sampleDoc         = XWPFTestDataSamples.OpenSampleDocument("Styles.docx");
            List <XWPFStyle> testUsedStyleList = new List <XWPFStyle>();
            XWPFStyles       styles            = sampleDoc.GetStyles();
            XWPFStyle        style             = styles.GetStyle("berschrift1");

            testUsedStyleList.Add(style);
            testUsedStyleList.Add(styles.GetStyle("Standard"));
            testUsedStyleList.Add(styles.GetStyle("berschrift1Zchn"));
            testUsedStyleList.Add(styles.GetStyle("Absatz-Standardschriftart"));
            style.HasSameName(style);

            List <XWPFStyle> usedStyleList = styles.GetUsedStyleList(style);

            //Assert.AreEqual(usedStyleList, testUsedStyleList);
            Assert.AreEqual(usedStyleList.Count, testUsedStyleList.Count);
            for (int i = 0; i < usedStyleList.Count; i++)
            {
                Assert.AreEqual(usedStyleList[i], testUsedStyleList[i]);
            }
        }