当前位置:网站首页>Npoi create word
Npoi create word
2022-06-12 21:33:00 【Caozhenhua】
effect

Code
using NPOI.OpenXmlFormats.Wordprocessing;
using NPOI.SS.UserModel;
using NPOI.XWPF.UserModel;
using System;
using System.IO;
namespace NPOIWord
{
class Program
{
static void Main(string[] args)
{
string path = Path.Combine(Directory.GetCurrentDirectory()
, "word", Guid.NewGuid() + ".docx");
Save_Word(path);
}
private static void Save_Word(string path)
{
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
{
// Initialize document
XWPFDocument m_Doc = new XWPFDocument();
#region Create paragraphs
XWPFParagraph paragraph = m_Doc.CreateParagraph();
paragraph.Alignment = ParagraphAlignment.CENTER;
paragraph.SpacingBeforeLines = 40;
paragraph.SpacingAfterLines = 40;
XWPFRun run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 14;
run.IsBold = true;
run.SetText(" Xi'an two-day tour itinerary ");
paragraph = m_Doc.CreateParagraph();
paragraph.Alignment = ParagraphAlignment.LEFT;
paragraph.SpacingBeforeLines = 40;
paragraph.SpacingAfterLines = 40;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" One 、 Itinerary features ");
paragraph = m_Doc.CreateParagraph();
paragraph.SpacingAfterLines = 40;
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.SetText(" Test, test, test, test, test ");
paragraph = m_Doc.CreateParagraph();
paragraph.SpacingBeforeLines = 40;
paragraph.SpacingAfterLines = 40;
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" Two 、 Target customers ");
paragraph = m_Doc.CreateParagraph();
paragraph.SpacingAfterLines = 40;
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.SetText(" Test, test, test, test, test ");
paragraph = m_Doc.CreateParagraph();
paragraph.SpacingBeforeLines = 40;
paragraph.SpacingAfterLines = 40;
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" 3、 ... and 、 Travel arrangements ");
#endregion
#region Create a table
XWPFTable table = m_Doc.CreateTable(3, 4);
table.Width = 5000;
#region first line
CT_P para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" date ");
table.GetRow(0).GetCell(0).SetColor("#d1d1d2");
table.GetRow(0).GetCell(0).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" Travel arrangements ");
table.GetRow(0).GetCell(1).SetColor("#d1d1d2");
table.GetRow(0).GetCell(1).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" Have meals ");
table.GetRow(0).GetCell(2).SetColor("#d1d1d2");
table.GetRow(0).GetCell(2).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" accommodation ");
table.GetRow(0).GetCell(3).SetColor("#d1d1d2");
table.GetRow(0).GetCell(3).SetParagraph(paragraph);
#endregion
#region The second line
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText("D1");
table.GetRow(1).GetCell(0).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" Xi'an ");
table.GetRow(1).GetCell(1).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText("--, in , On the evening of ");
table.GetRow(1).GetCell(2).SetParagraph(paragraph);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.CENTER;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 12;
run.IsBold = true;
run.SetText(" Xi'an ");
table.GetRow(1).GetCell(3).SetParagraph(paragraph);
#endregion
#region The third line
// Merge
table.GetRow(2).MergeCells(0, 3);
para = new CT_P();
paragraph = new XWPFParagraph(para, table.Body);
paragraph.SpacingBeforeLines = 20;
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 10;
run.SetText(" 08:30 Xi'an New Town Plaza collection ");
table.GetRow(2).GetCell(0).SetParagraph(paragraph);
// Line break
run = paragraph.CreateRun();
run.AddBreak(BreakType.TEXTWRAPPING);
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 10;
run.SetText(" 08:30 Xi'an New Town Plaza collection ");
table.GetRow(2).GetCell(0).SetParagraph(paragraph);
run = paragraph.CreateRun();
run.AddBreak(BreakType.TEXTWRAPPING);
paragraph = new XWPFParagraph(para, table.Body);
paragraph.Alignment = ParagraphAlignment.LEFT;
run = paragraph.CreateRun();
run.FontFamily = " Song style ";
run.FontSize = 10;
run.SetText(" 08:30 Xi'an New Town Plaza collection ");
table.GetRow(2).GetCell(0).SetParagraph(paragraph);
#endregion
#endregion
//5、 Write to file
m_Doc.Write(fs);
}
}
}
}
边栏推荐
- Lintcode:127. Topology sorting
- leetcode:207. 课程表
- Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
- 好数对的求解
- Ubuntu16.04 completely delete MySQL database
- Rearrangement exercises
- NIO使用指南
- Icml2022 | Galaxy: apprentissage actif des cartes de polarisation
- String Basics
- A blog written clearly by vit
猜你喜欢

Icml2022 | Galaxy: apprentissage actif des cartes de polarisation

Leetcode: 210. Programme II

leetcode:207. Class Schedule Card

Image processing 12- image linear blending

ICML2022 | GALAXY:極化圖主動學習

How do complex systems detect anomalies? North Carolina UNCC and others' latest overview of graph based deep learning anomaly detection methods in complex distributed systems describes the latest prog

Lintcode:127. Topology sorting

图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?

SQL调优指南笔记16:Managing Historical Optimizer Statistics

Distributed cloud service developer'allegro Xile technology 'received an angel round financing of US $3million
随机推荐
How to design a message box through draftjs
Module 8: Design message queue MySQL table for storing message data
JUC并发工具包使用指南
ORM 实现类与表,类属性与字段的映射关系
Research Report on market supply and demand and strategy of China's hydraulic hammer industry
Test basis: unit test
Teamwork collaboration application experience sharing | community essay solicitation
zgc的垃圾收集的主要階段
ICML2022 | GALAXY:極化圖主動學習
GPU giant NVIDIA suffered a "devastating" network attack, and the number one malware shut down its botnet infrastructure | global network security hotspot on February 28
Recursively call knowledge points - including example solving binary search, frog jumping steps, reverse order output, factorial, Fibonacci, Hanoi tower.
Oracle 19c 安装文档
插入排序
Cv2.lut() (populates the output array with values from the lookup table)
图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
ASCII 码对照表
SQL调优指南笔记16:Managing Historical Optimizer Statistics
Yanghui triangle code implementation
好数对的求解
#113 Path Sum II