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


C# XWPFDocument.Write方法代码示例

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


在下文中一共展示了XWPFDocument.Write方法的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)
        {
            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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: Main

 static void Main(string[] args)
 {
     string filePath = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + @"\data\" + "Convert Word Doc to Other Formats.doc";
     XWPFDocument wordDocument = new XWPFDocument();
     FileStream out1 = new FileStream(filePath, FileMode.Open); 
     using (FileStream sw = File.Create("Convert Word Doc to Other Formatsblank.docx"))
     {               
         wordDocument.Write(sw);
     }
     
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:11,代码来源:Program.cs

示例9: integration

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

            XWPFParagraph p1 = doc.CreateParagraph();

            XWPFRun r1 = p1.CreateRun();
            r1.SetText("Lorem ipsum dolor sit amet.");
            doc.IsTrackRevisions = (true);

            MemoryStream out1 = new MemoryStream();
            doc.Write(out1);

            MemoryStream inputStream = new MemoryStream(out1.ToArray());
            XWPFDocument document = new XWPFDocument(inputStream);
            inputStream.Close();

            Assert.IsTrue(document.IsTrackRevisions);
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:19,代码来源:TestChangeTracking.cs

示例10: Main

        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetText("test");


            var widthEmus = (int)(400.0 * 9525);
            var heightEmus = (int)(300.0 * 9525);

            using (FileStream picData = new FileStream("../../image/HumpbackWhale.jpg", FileMode.Open, FileAccess.Read))
            {
                r2.AddPicture(picData, (int)PictureType.PNG, "image1", widthEmus, heightEmus);
            }
            using (FileStream sw = File.Create("test.docx"))
            {
                doc.Write(sw);
            }
        }
开发者ID:89sos98,项目名称:npoi,代码行数:20,代码来源:Program.cs

示例11: word_creat_one

 /// <summary>
 /// 生成一个工程的word文件
 /// </summary>
 /// <param name="datalist">当前工程的数据List</param>
 /// <param name="outputPath">word文件输出路径</param>
 public static void word_creat_one(List<DbBean> datalist, string outputPath)
 {
     XWPFDocument m_Docx = new XWPFDocument();
     word_init(m_Docx);
     //内容
     for (int i = 0; i < datalist.Count; i++)
     {
         word_inster_table(m_Docx, datalist[i], i + 1);
         //TODO 此处插入图片
         word_insert_picture(m_Docx, datalist[i].PrjName, datalist[i].PhotoPathName);
     }
     //输出
     FileStream sw = null;
     try
     {
         sw = File.Create(outputPath);
         if (m_Docx == null)
         {
             Log.Err(TAG, "m_Docx is null");
         }
         if (sw == null)
         {
             Log.Err(TAG, "sw is null");
         }
         m_Docx.Write(sw);
         sw.Close();
     }
     catch
     {
         Log.Err(TAG, "something is wrong");
     }
     finally
     {
         sw.Close();
     }
 }
开发者ID:ssthouse,项目名称:NpoiTest,代码行数:41,代码来源:WordGenerator.cs

示例12: TestIntegration

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

            XWPFParagraph p1 = doc.CreateParagraph();

            XWPFRun r1 = p1.CreateRun();
            r1.SetText("Lorem ipsum dolor sit amet.");
            doc.EnforceCommentsProtection();

            FileInfo tempFile = TempFile.CreateTempFile("documentProtectionFile", ".docx");
            if (File.Exists(tempFile.FullName))
                File.Delete(tempFile.FullName);
            Stream out1 = new FileStream(tempFile.FullName, FileMode.CreateNew);

            doc.Write(out1);
            out1.Close();

            FileStream inputStream = new FileStream(tempFile.FullName, FileMode.Open);
            XWPFDocument document = new XWPFDocument(inputStream);
            inputStream.Close();

            Assert.IsTrue(document.IsEnforcedCommentsProtection());
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:24,代码来源:TestDocumentProtection.cs

示例13: GetExportStream

        /// <summary>
        /// Returns stream result of the export process.
        /// </summary>
        /// <param name="moduleNames">Modules to export.</param>
        /// <param name="instanceInfo">Instance for which to execute modules.</param>
        /// <returns>Result stream</returns>
        public Stream GetExportStream(IEnumerable<string> moduleNames, IInstanceInfo instanceInfo)
        {
            // Create docx
            XWPFDocument document = null;
            try
            {
                // Open docx template
                document = new XWPFDocument(new FileInfo(@"Data\Templates\KInspectorReportTemplate.docx").OpenRead());
            }
            catch
            {
                // Create blank
                document = new XWPFDocument();
            }

            // Create sumary paragraph containing results of text modules, and sumary of all other modules.
            document.CreateParagraph("Result summary");
            XWPFTable resultSummary = document.CreateTable();
            resultSummary.GetRow(0).FillRow("Module", "Result", "Comment", "Description");

            // Run every module and write its result.
            foreach (string moduleName in moduleNames.Distinct())
            {
                var module = ModuleLoader.GetModule(moduleName);
                var result = module.GetResults(instanceInfo);
                var meta = module.GetModuleMetadata();

                switch (result.ResultType)
                {
                    case ModuleResultsType.String:
                        resultSummary.CreateRow().FillRow(moduleName, result.Result as string, result.ResultComment, meta.Comment);
                        break;
                    case ModuleResultsType.List:
                        document.CreateParagraph(moduleName);
                        document.CreateParagraph(result.ResultComment);
                        document.CreateTable().FillTable(result.Result as IEnumerable<string>);
                        resultSummary.CreateRow().FillRow(moduleName, "See details bellow", result.ResultComment, meta.Comment);
                        break;
                    case ModuleResultsType.Table:
                        document.CreateParagraph(moduleName);
                        document.CreateParagraph(result.ResultComment);
                        document.CreateTable().FillRows(result.Result as DataTable);
                        resultSummary.CreateRow().FillRow(moduleName, "See details bellow", result.ResultComment, meta.Comment);
                        break;
                    case ModuleResultsType.ListOfTables:
                        document.CreateParagraph(moduleName);
                        document.CreateParagraph(result.ResultComment);
                        DataSet data = result.Result as DataSet;
                        if (data == null)
                        {
                            resultSummary.CreateRow().FillRow(moduleName, "Internal error: Invalid DataSet", result.ResultComment, meta.Comment);
                            break;
                        }

                        foreach (DataTable tab in data.Tables)
                        {
                            // Create header
                            document.CreateParagraph(tab.TableName);

                            // Write data
                            document.CreateTable().FillRows(tab);
                        }

                        resultSummary.CreateRow().FillRow(moduleName, "See details bellow", result.ResultComment, meta.Comment);
                        break;
                    default:
                        resultSummary.CreateRow().FillRow(moduleName, "Internal error: Unknown module", result.ResultComment, meta.Comment);
                        continue;
                }
            }

            // XWPFDocument.Write closes the stream. NpoiMemoryStream is used to prevent it.
            NpoiMemoryStream stream = new NpoiMemoryStream(false);
            document.Write(stream);
            stream.Seek(0, SeekOrigin.Begin);
            stream.AllowClose = true;

            return stream;
        }
开发者ID:ChristopherJennings,项目名称:KInspector,代码行数:85,代码来源:ExportDocx.cs

示例14: SimpleDocument


//.........这里部分代码省略.........
                XWPFRun r1 = p1.CreateRun();
                r1.SetBold(true);
                r1.SetText("The quick brown fox");
                r1.SetBold(true);
                r1.SetFontFamily("Courier");
                r1.SetUnderline(UnderlinePatterns.DotDotDash);
                r1.SetTextPosition(100);


                XWPFParagraph p2 = doc.CreateParagraph();
                p2.SetAlignment(ParagraphAlignment.RIGHT);


                //BORDERS
                p2.SetBorderBottom(Borders.DOUBLE);
                p2.SetBorderTop(Borders.DOUBLE);
                p2.SetBorderRight(Borders.DOUBLE);
                p2.SetBorderLeft(Borders.DOUBLE);
                p2.SetBorderBetween(Borders.SINGLE);


                XWPFRun r2 = p2.CreateRun();
                r2.SetText("jumped over the lazy dog");
                r2.SetStrike(true);
                r2.SetFontSize(20);


                XWPFRun r3 = p2.CreateRun();
                r3.SetText("and went away");
                r3.SetStrike(true);
                r3.SetFontSize(20);
                r3.SetSubscript(VerticalAlign.SUPERSCRIPT);




                XWPFParagraph p3 = doc.CreateParagraph();


                p3.SetPageBreak(true);


                //p3.SetAlignment(ParagraphAlignment.DISTRIBUTE);
                p3.SetAlignment(ParagraphAlignment.BOTH);
                p3.SetSpacingLineRule(LineSpacingRule.EXACT);

                p3.IndentationFirstLine = 600;
                //p3.IndentationFirstLine(600);




                XWPFRun r4 = p3.CreateRun();
                r4.SetTextPosition(20);
                r4.SetText("To be, or not to be: that is the question: "
                        + "Whether 'tis nobler in the mind to suffer "
                        + "The slings and arrows of outrageous fortune, "
                        + "Or to take arms against a sea of troubles, "
                        + "And by opposing end them? To die: to sleep; ");
                r4.AddBreak(BreakType.PAGE);
                r4.SetText("No more; and by a sleep to say we end "
                        + "The heart-ache and the thousand natural shocks "
                        + "That flesh is heir to, 'tis a consummation "
                        + "Devoutly to be wish'd. To die, to sleep; "
                        + "To sleep: perchance to dream: ay, there's the rub; "
                        + ".......");

                //r4.SetItalic(true);
                //This would imply that this break shall be treated as a simple line break, and break the line after that word:


                XWPFRun r5 = p3.CreateRun();
                r5.SetTextPosition(-10);
                r5.SetText("For in that sleep of death what dreams may come");
                r5.AddCarriageReturn();
                r5.SetText("When we have shuffled off this mortal coil,"
                        + "Must give us pause: there's the respect"
                        + "That makes calamity of so long life;");
                r5.AddBreak();
                r5.SetText("For who would bear the whips and scorns of time,"
                        + "The oppressor's wrong, the proud man's contumely,");


                r5.AddBreak(BreakClear.ALL);
                r5.SetText("The pangs of despised love, the law's delay,"
                        + "The insolence of office and the spurns" + ".......");


                FileStream out1 = new FileStream(filepath, FileMode.Create);
                doc.Write(out1);
                out1.Close();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }
开发者ID:yuyi1,项目名称:Verdezyne-Operations,代码行数:101,代码来源:DocxWriter.cs

示例15: CreateContractCheckResult

        public static void CreateContractCheckResult(string fileName, Model.ContractCheckResult result)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph pTitle = doc.CreateParagraph();
            pTitle.Alignment = ParagraphAlignment.CENTER;
            XWPFRun rText = pTitle.CreateRun();
            rText.IsBold = true;
            rText.FontSize = 18;
            rText.SetText("客户管理系统合同数据检查结果报告");

            XWPFParagraph pDesc = doc.CreateParagraph();
            pDesc.Alignment = ParagraphAlignment.RIGHT;
            rText = pDesc.CreateRun();
            rText.IsBold = false;
            rText.SetColor("#ff0000");
            rText.FontSize = 8;
            rText.SetText("*本报告仅供参考,实际结果以客户管理系统为准");
            XWPFParagraph pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("一、合同概况:");

            if (!string.IsNullOrEmpty(result.ContractSurvey))
            {
                string[] strList = result.ContractSurvey.Split(new char[] { '$' });
                foreach (string item in strList)
                {
                    pContent = doc.CreateParagraph();
                    rText = pContent.CreateRun();
                    rText.SetText("        " + item);
                }
            }

            pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("二、检查结果:");

            pContent = doc.CreateParagraph();
            rText = pContent.CreateRun();
            rText.SetText("        " + result.CheckResult);

            pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("三、检查规则:");

            if (!string.IsNullOrEmpty(result.CheckRule))
            {
                string[] strList = result.CheckRule.Split(new char[] { '$' });
                foreach (string item in strList)
                {
                    pContent = doc.CreateParagraph();
                    rText = pContent.CreateRun();
                    rText.SetText("        " + item);
                }
            }

            FileStream sw = File.Create(fileName);
            doc.Write(sw);
            sw.Close();
            try
            {
                Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document wordDocument = new Microsoft.Office.Interop.Word.Document();
                Object nothing = System.Reflection.Missing.Value;
                Object filePath = fileName;
                wordApplication.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref   nothing, ref   nothing, ref   nothing, ref   nothing, ref  nothing, ref   nothing, ref   nothing);
                wordDocument = wordApplication.ActiveDocument;
                wordApplication.Visible = true;
            }
            catch { }
        }
开发者ID:AllanHao,项目名称:MotivationManager,代码行数:76,代码来源:WordController.cs


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