Пример #1
0
        private static void WriteByReadTemplate()
        {
            using (var dotStream = new FileStream("read.docx", FileMode.Open, FileAccess.Read))
            {
                XWPFDocument template = new XWPFDocument(dotStream);

                using (var fileStream = new FileStream("test.docx", FileMode.Create, FileAccess.Write))
                {
                    XWPFDocument document  = new XWPFDocument();
                    XWPFStyles   newStyles = document.CreateStyles();
                    newStyles.SetStyles(template.GetCTStyle());

                    XWPFParagraph paragraph = document.CreateParagraph();
                    paragraph.Style = "a3";
                    XWPFRun xwpfRun = paragraph.CreateRun();
                    xwpfRun.SetText("标题内容");

                    XWPFParagraph paragraph1 = document.CreateParagraph();
                    paragraph1.Style = "1";
                    XWPFRun xwpfRun1 = paragraph1.CreateRun();
                    xwpfRun1.SetText("标题1内容");

                    XWPFParagraph paragraph2 = document.CreateParagraph();
                    paragraph2.Style = "2";
                    XWPFRun xwpfRun2 = paragraph2.CreateRun();
                    xwpfRun2.SetText("标题2内容");

                    document.Write(fileStream);

                    document.Close();
                }
                template.Close();
            }
        }
Пример #2
0
        public void TestSetStyles_Bug57254()
        {
            XWPFDocument docOut = new XWPFDocument();
            XWPFStyles   styles = docOut.CreateStyles();

            CT_Styles ctStyles   = new CT_Styles();
            String    strStyleId = "headline1";
            CT_Style  ctStyle    = ctStyles.AddNewStyle();

            ctStyle.styleId = (/*setter*/ strStyleId);
            styles.SetStyles(ctStyles);

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

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            styles = docIn.GetStyles();
            Assert.IsTrue(styles.StyleExist(strStyleId));
        }
Пример #3
0
 public CT_Styles Build()
 {
     documentStyles.SetStyles(ctStyles);
     return(ctStyles);
 }