當前位置: 首頁>>代碼示例>>C#>>正文


C# UserModel.XWPFDocument類代碼示例

本文整理匯總了C#中NPOI.XWPF.UserModel.XWPFDocument的典型用法代碼示例。如果您正苦於以下問題:C# XWPFDocument類的具體用法?C# XWPFDocument怎麽用?C# XWPFDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XWPFDocument類屬於NPOI.XWPF.UserModel命名空間,在下文中一共展示了XWPFDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的NPOI.XWPF.UserModel.XWPFDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。