当前位置: 首页>>代码示例>>C#>>正文


C# UserModel.XWPFDocument类代码示例

本文整理汇总了C#中NPOI.XWPF.UserModel.XWPFDocument的典型用法代码示例。如果您正苦于以下问题:C# XWPFDocument类的具体用法?C# XWPFDocument怎么用?C# XWPFDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

XWPFDocument类属于NPOI.XWPF.UserModel命名空间,在下文中一共展示了XWPFDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph para= doc.CreateParagraph();
            XWPFRun r0 = para.CreateRun();
            r0.SetText("Title1");
            para.BorderTop = Borders.THICK;
            para.FillBackgroundColor = "EEEEEE";
            para.FillPattern = NPOI.OpenXmlFormats.Wordprocessing.ST_Shd.diagStripe;

            XWPFTable table = doc.CreateTable(3, 3);

            table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");

            XWPFTableCell c1 = table.GetRow(0).GetCell(0);
            XWPFParagraph p1 = c1.AddParagraph();   //don't use doc.CreateParagraph
            XWPFRun r1 = p1.CreateRun();
            r1.SetText("The quick brown fox");
            r1.SetBold(true);

            r1.FontFamily = "Courier";
            r1.SetUnderline(UnderlinePatterns.DotDotDash);
            r1.SetTextPosition(100);
            c1.SetColor("FF0000");
            

            table.GetRow(2).GetCell(2).SetText("only text");

            FileStream out1 = new FileStream("simpleTable.docx", FileMode.Create);
            doc.Write(out1);
            out1.Close();
        }
开发者ID:JustinChangTW,项目名称:npoi,代码行数:32,代码来源:Program.cs


示例2: Main

        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument(new FileStream("data/Extract Images from Word Document.doc",FileMode.Open));
            IList<XWPFPictureData> pics = doc.AllPictures;

            foreach (XWPFPictureData pic in pics)
            {
                FileStream outputStream = new FileStream("data/NPOI_" + pic.FileName,FileMode.OpenOrCreate);
               byte[] picData= pic.Data;
                outputStream.Write(picData, 0, picData.Length);
                outputStream.Close();
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:13,代码来源:Program.cs


示例3: WriteOutAndReadBack

 public static XWPFDocument WriteOutAndReadBack(XWPFDocument doc)
 {
     MemoryStream baos = new MemoryStream(4096);
     doc.Write(baos);
     MemoryStream bais = new MemoryStream(baos.ToArray());
     return new XWPFDocument(bais);
 }
开发者ID:89sos98,项目名称:npoi,代码行数:7,代码来源:XWPFTestDataSamples.cs


示例4: SetUp

        public void SetUp()
        {
            XWPFDocument doc = new XWPFDocument();
            p = doc.CreateParagraph();

            this.ctRun = new CT_R();
        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:7,代码来源:TestXWPFRun.cs


示例5: FindTable

 public DataTable FindTable(string filepath)
 {
     try
     {
         using (FileStream stream = File.OpenRead(filepath))
         {
             XWPFDocument doc = new XWPFDocument(stream);
             foreach (XWPFTable table in doc.Tables)
             {
                 if (Row2Cell1Contains(table, @"Run") && Row1Cell1Contains(table, @"General"))
                 {
                     return WordTableToDataTable.GetDataTable(table);
                 }
             }
             return null;
         }
     }
     catch (AccessViolationException avex)
     {
         throw new AccessViolationException(string.Format("You do not have permission to access the file " + avex.Message));
     }
     catch (System.IO.IOException ioex)
     {
         throw new System.IO.IOException(ioex.Message.Replace("\'", "<br />") + "<br /><br />Someone has file open and it is therefore locked.");
     }
     
 }
开发者ID:yuyi1,项目名称:Verdezyne-Operations,代码行数:27,代码来源:FermentationOutlineTable.cs


示例6: LoadFile

 public void LoadFile(String path)
 {
     using(var file = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         _document = new XWPFDocument(file);
     }
 }
开发者ID:aifabregaz,项目名称:Reverse-Dictionary,代码行数:7,代码来源:DocxTextLoader.cs


示例7: Main

        static void Main(string[] args)
        {             

            // Create a new document from scratch
            XWPFDocument doc = new XWPFDocument();
            XWPFTable table = doc.CreateTable(3, 3);

            table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");

            XWPFTableCell c1 = table.GetRow(0).GetCell(0);
            XWPFParagraph p1 = c1.AddParagraph();   //don't use doc.CreateParagraph
            XWPFRun r1 = p1.CreateRun();
            r1.SetText("This is test table contents");
            r1.SetBold(true);
 
            r1.FontFamily = "Courier";
            r1.SetUnderline(UnderlinePatterns.DotDotDash);
            r1.SetTextPosition(100);
            c1.SetColor("FF0000");


            table.GetRow(2).GetCell(2).SetText("only text");

            FileStream out1 = new FileStream("Format Table in Document.docx", FileMode.Create);
            doc.Write(out1);
            out1.Close();
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:27,代码来源:Program.cs


示例8: TestSetGetVertAlignment

        public void TestSetGetVertAlignment()
        {
            // instantiate the following classes so they'll Get picked up by
            // the XmlBean process and Added to the jar file. they are required
            // for the following XWPFTableCell methods.
            CT_Shd ctShd = new CT_Shd();
            Assert.IsNotNull(ctShd);
            CT_VerticalJc ctVjc = new CT_VerticalJc();
            Assert.IsNotNull(ctVjc);
            ST_Shd stShd = ST_Shd.nil;
            Assert.IsNotNull(stShd);
            ST_VerticalJc stVjc = ST_VerticalJc.top;
            Assert.IsNotNull(stVjc);

            // create a table
            XWPFDocument doc = new XWPFDocument();
            CT_Tbl ctTable = new CT_Tbl();
            XWPFTable table = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);
            Assert.IsNotNull(tr);
            // row has a single cell by default; grab it
            XWPFTableCell cell = tr.GetCell(0);

            cell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH);
            XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment();
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:28,代码来源:TestXWPFTableCell.cs


示例9: TestWord

 public void TestWord()
 {
     POIXMLDocument doc = new XWPFDocument(
             POIDataSamples.GetDocumentInstance().OpenResourceAsStream("WordWithAttachments.docx")
     );
     Test(doc, 5);
 }
开发者ID:ctddjyds,项目名称:npoi,代码行数:7,代码来源:TestEmbeded.cs


示例10: TestCreateRow

        public void TestCreateRow()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            CT_Row r1 = table.AddNewTr();
            r1.AddNewTc().AddNewP();
            r1.AddNewTc().AddNewP();
            CT_Row r2 = table.AddNewTr();
            r2.AddNewTc().AddNewP();
            r2.AddNewTc().AddNewP();
            CT_Row r3 = table.AddNewTr();
            r3.AddNewTc().AddNewP();
            r3.AddNewTc().AddNewP();

            XWPFTable xtab = new XWPFTable(table, doc);
            Assert.AreEqual(3, xtab.GetNumberOfRows());
            Assert.IsNotNull(xtab.GetRow(2));

            //add a new row
            xtab.CreateRow();
            Assert.AreEqual(4, xtab.GetNumberOfRows());

            //check number of cols
            Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());

            //check creation of first row
            xtab = new XWPFTable(new CT_Tbl(), doc);
            Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:30,代码来源:TestXWPFTable.cs


示例11: XWPFHeader

 public XWPFHeader(XWPFDocument doc, CT_HdrFtr hdrFtr)
     : base(doc, hdrFtr)
 {
     /*
     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);
         }
         if (o is CTTbl) {
             XWPFTable t = new XWPFTable((CTTbl) o, this);
             tables.Add(t);
         }
     }
     cursor.Dispose();*/
     foreach (object o in hdrFtr.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             paragraphs.Add(p);
         }
         if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             tables.Add(t);
         }
     }
 }
开发者ID:hanwangkun,项目名称:npoi,代码行数:32,代码来源:XWPFHeader.cs


示例12: Bug55802

        public void Bug55802()
        {
            String blabla =
                "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" +
                "\nalt\u0131, yedi, sekiz, dokuz, on.\n" +
                "\nK\u0131rm\u0131z\u0131 don,\n" +
                "\ngel bizim bah\u00e7eye kon,\n" +
                "\nsar\u0131 limon";
            XWPFDocument doc = new XWPFDocument();
            XWPFRun run = doc.CreateParagraph().CreateRun();

            foreach (String str in blabla.Split("\n".ToCharArray()))
            {
                run.SetText(str);
                run.AddBreak();
            }

            run.FontFamily = (/*setter*/"Times New Roman");
            run.FontSize = (/*setter*/20);
            Assert.AreEqual(run.FontFamily, "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.CS), "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.EastAsia), "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Times New Roman");
            run.SetFontFamily("Arial", FontCharRange.HAnsi);
            Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Arial");
        }
开发者ID:eatage,项目名称:npoi,代码行数:26,代码来源:TestXWPFBugs.cs


示例13: Main

        static void Main(string[] args)
        {
            if (args.Length != 2)
                return;

            string src = args[0];
            string target = args[1];
            

            RunMode mode= RunMode.Excel;
            if (src.Contains(".docx"))
                mode = RunMode.Word;

            if (mode == RunMode.Excel)
            {
                Stream rfs = File.OpenRead(src);
                IWorkbook workbook = new XSSFWorkbook(rfs);
                rfs.Close();
                using (FileStream fs = File.Create(target))
                {
                    workbook.Write(fs);
                }
            }
            else
            {
                Stream rfs = File.OpenRead(src);
                XWPFDocument workbook = new XWPFDocument(rfs);
                rfs.Close();
                using (FileStream fs = File.Create(target))
                {
                    workbook.Write(fs);
                }
            }
        }
开发者ID:89sos98,项目名称:npoi,代码行数:34,代码来源:Program.cs


示例14: GetHyperlink

        /**
         * If this Hyperlink is an external reference hyperlink,
         *  return the object for it.
         */
        public XWPFHyperlink GetHyperlink(XWPFDocument document)
        {
            String id = GetHyperlinkId();
            if (id == null)
                return null;

            return document.GetHyperlinkByID(id);
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:12,代码来源:XWPFHyperlinkRun.cs


示例15: Main

 static void Main(string[] args)
 {
     XWPFDocument doc = new XWPFDocument();
     doc.CreateParagraph();
     FileStream sw = File.OpenWrite("blank.docx");
     doc.Write(sw);
     sw.Close();
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:8,代码来源:Program.cs


示例16: verifyOneHeaderPicture

        private void verifyOneHeaderPicture(XWPFDocument sampleDoc)
        {
            XWPFHeaderFooterPolicy policy = sampleDoc.GetHeaderFooterPolicy();

            XWPFHeader header = policy.GetDefaultHeader();

            IList<XWPFPictureData> pictures = header.AllPictures;
            Assert.AreEqual(1, pictures.Count);
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:9,代码来源:TestXWPFPictureData.cs


示例17: Main

 static void Main(string[] args)
 {
     XWPFDocument wordDocument = new XWPFDocument(new FileStream("data/Working with Footers.doc", FileMode.Open));
     IList<XWPFFooter> footers = wordDocument.FooterList;
     foreach (XWPFFooter footer in footers)
     {
         Console.WriteLine(footer.Text);
     }
 }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:9,代码来源:Program.cs


示例18: Main

        static void Main(string[] args)
        {
            XWPFDocument  wordDocument = new XWPFDocument( new FileStream("data/Convert Word Doc to Other Formats.doc", FileMode.Open));

            using (FileStream sw = File.Create("data/Convert Word Doc to Other Formatsblank.docx"))
            {
                wordDocument.Write(sw);
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:9,代码来源:Program.cs


示例19: Main

 static void Main(string[] args)
 {
     XWPFDocument doc = new XWPFDocument();
     doc.CreateParagraph();
     using (FileStream sw = File.Create("blank.docx"))
     {
         doc.Write(sw);
     }
 }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:9,代码来源:Program.cs


示例20: Extract

        public static String Extract(String url, String saveTo = null)
        {
            try
            {
                WebClient wc = new WebClient();
                byte[] data = wc.DownloadData(url);

                // 如果设置了保存到文件,则写入文件
                if (!String.IsNullOrWhiteSpace(saveTo) && data != null && data.Length > 0)
                {
                    if (!Directory.Exists(saveTo))
                    {
                        Directory.CreateDirectory(saveTo);
                    }
                    String file = GeneratePath(saveTo, url);
                    try
                    {
                        using (FileStream fs = new FileStream(file, FileMode.CreateNew))
                        {
                            fs.Write(data, 0, data.Length);
                        }
                    }
                    catch (IOException ioe)
                    {
                    }
                }

                using (MemoryStream ms = new MemoryStream(data))
                {
                    XWPFDocument doc = new XWPFDocument(ms);

                    StringBuilder wholeDocument = new StringBuilder();

                    foreach (XWPFParagraph para in doc.Paragraphs)
                    {
                        String text = para.Text;
                        wholeDocument.Append(text);
                    }

                    foreach (XWPFTable table in doc.Tables)
                    {
                        String text = table.Text;
                        if (!String.IsNullOrWhiteSpace(text))
                        {
                            text = text.Replace("\t", String.Empty);
                        }
                        wholeDocument.Append(text);
                    }

                    return wholeDocument.ToString();
                }
            }
            catch (Exception e)
            {
                return String.Empty;
            }
        }
开发者ID:TaikorInc,项目名称:FalcoA,代码行数:57,代码来源:WordParser.cs



注:本文中的NPOI.XWPF.UserModel.XWPFDocument类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。