本文整理汇总了C#中NPOI.XWPF.UserModel.XWPFDocument.CreateTable方法的典型用法代码示例。如果您正苦于以下问题:C# XWPFDocument.CreateTable方法的具体用法?C# XWPFDocument.CreateTable怎么用?C# XWPFDocument.CreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.XWPF.UserModel.XWPFDocument
的用法示例。
在下文中一共展示了XWPFDocument.CreateTable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: 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();
}
示例3: NPOIWord
static void NPOIWord()
{
// Word的单元是段落,所以我们在空文件中创建一个新的段落
XWPFDocument doc = new XWPFDocument();
XWPFParagraph ph = doc.CreateParagraph();
ph.Alignment = ParagraphAlignment.CENTER;
ph.BorderBottom = Borders.DOUBLE;
ph.BorderTop = Borders.DOUBLE;
ph.BorderRight = Borders.DOUBLE;
ph.BorderLeft = Borders.DOUBLE;
XWPFRun run = ph.CreateRun();
run.SetBold(true);
run.SetText("你这是在自寻死路");
// 可以设置paragraph中文本的样式,包括字体,大小,粗细已经删除线等。
// 此处都是基于XWPFRun来进行设置的,但是注意paragraph中的段落对齐方式是在
// XWPFParagraph中设置的。
run.FontFamily = "仿宋";
run.FontSize = 20;
run.IsItalic = true;
run.SetStrike(true);
// 在Word中创建表格
XWPFTable table = doc.CreateTable(3, 3);
table.GetRow(1).GetCell(1).SetText("Example of table");
// 可以把单元格的内容设置为paragraph实例
XWPFParagraph pCha = doc.CreateParagraph();
// 注意文本的样式都是基于XWPFRun来进行设置的,除了段落的对齐方式,是paragraph为基准进行设置的
XWPFRun r1 = pCha.CreateRun();
r1.SetBold(true);
r1.FontSize = 15;
r1.SetText("The quick brown fox1");
r1.FontFamily = "Courier";
r1.SetUnderline(UnderlinePatterns.DotDotDash);
r1.SetTextPosition(100);
table.GetRow(0).GetCell(0).SetParagraph(pCha);
table.GetRow(2).GetCell(2).SetText("Only Text");
FileStream fs = File.Create(@"D:\blank.docx");
pCha.AddRun(r1);
doc.Write(fs);
fs.Close();
}
示例4: 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;
}
示例5: word_init
/// <summary>
/// 生成模板文件
/// </summary>
/// <param name="m_Docx">根文档</param>
private static void word_init(XWPFDocument m_Docx)
{
//1‘=1440twip=25.4mm=72pt(磅point)=96px(像素pixel)
//1px(像素pixel)=0.75pt(磅point)
// A4:W=11906 twip=8.269''=210mm,h=16838twip=11.693''=297mm
//A5:W=8390 twip=5.827''=148mm,h=11906 twip=8.269''=210mm
//A6:W=5953 twip=4.134''=105mm,h=8390twip=5.827''=1148mm
//16k195mmX270mm:
//16k184mmX260mm:
//16k197mmX273mm:
CT_SectPr m_SectPr = new CT_SectPr();
//页面设置A4纵向
m_SectPr.pgSz.w = (ulong) 11906;
m_SectPr.pgSz.h = (ulong) 16838;
m_Docx.Document.body.sectPr = m_SectPr;
//第一页
word_insert_space(4, m_Docx);
word_insert_text(m_Docx, "宋体", 22, "【项目名称】");
word_insert_text(m_Docx, "宋体", 22, "GSM-R 通信系统");
word_insert_text(m_Docx, "宋体", 22, "现场勘查报告");
word_insert_space(8, m_Docx);
word_insert_text(m_Docx, "宋体", 22, "【日期】");
word_insert_space(7, m_Docx);
//第二页
//表1
XWPFTable table = m_Docx.CreateTable(4, 2);
CT_Tbl ctbl = m_Docx.Document.body.GetTblArray()[0];
CT_TblPr ctblpr = ctbl.AddNewTblPr();
ctblpr.jc = new CT_Jc();
ctblpr.jc.val = ST_Jc.center;
table.Width = 4000;
table.GetRow(0).GetCell(0).SetText("项目");
table.GetRow(1).GetCell(0).SetText("日期");
table.GetRow(2).GetCell(0).SetText("现场勘查人员");
table.GetRow(3).GetCell(0).SetText("报告编制人员");
CT_TcPr m_Pr = table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
m_Pr.tcW = new CT_TblWidth();
m_Pr.tcW.w = "4000";
m_Pr.tcW.type = ST_TblWidth.dxa; //设置单元格宽度
word_insert_space(2, m_Docx);
word_insert_text(m_Docx, "宋体", 12, "基站勘察表");
}
示例6: word_inster_table
/// <summary>
/// word 插入表格功能(13行2列)
/// </summary>
/// <param name="m_Docx">根文档</param>
/// <param name="device_type">设备类型</param>
/// <param name="kilometer_mark">公里标</param>
/// <param name="side_direction">下行侧向</param>
/// <param name="longitude">经度</param>
/// <param name="latitude">纬度</param>
private static void word_inster_table(XWPFDocument m_Docx, DbBean bean, int i = 1)
{
XWPFTable table = m_Docx.CreateTable(12, 2);
CT_Tbl ctbl = m_Docx.Document.body.GetTblArray()[i];
CT_TblPr ctblpr = ctbl.AddNewTblPr();
ctblpr.jc = new CT_Jc();
ctblpr.jc.val = ST_Jc.center;
table.Width = 3500;
table.GetRow(0).GetCell(0).SetText("设备类型");
table.GetRow(0).GetCell(1).SetText(bean.DeviceType);
table.GetRow(1).GetCell(0).SetText("公里标");
table.GetRow(1).GetCell(1).SetText(bean.KilometerMark);
table.GetRow(2).GetCell(0).SetText("下行侧向");
table.GetRow(2).GetCell(1).SetText(bean.SideDirection);
table.GetRow(3).GetCell(0).SetText("距线路中心距离(m)");
table.GetRow(4).GetCell(0).SetText("经度");
table.GetRow(4).GetCell(1).SetText(bean.Longitude);
table.GetRow(5).GetCell(0).SetText("纬度");
table.GetRow(5).GetCell(1).SetText(bean.Latitude);
table.GetRow(6).GetCell(0).SetText("杆塔类型");
table.GetRow(6).GetCell(1).SetText(bean.TowerType);
table.GetRow(7).GetCell(0).SetText("杆塔高度");
table.GetRow(7).GetCell(1).SetText(bean.TowerHeight);
table.GetRow(8).GetCell(0).SetText("天线1方向角");
table.GetRow(8).GetCell(1).SetText(bean.AntennaDirection1);
table.GetRow(9).GetCell(0).SetText("天线2方向角");
table.GetRow(9).GetCell(1).SetText(bean.AntennaDirection2);
table.GetRow(10).GetCell(0).SetText("天线3方向角");
table.GetRow(10).GetCell(1).SetText(bean.AntennaDirection3);
table.GetRow(11).GetCell(0).SetText("天线4方向角");
table.GetRow(11).GetCell(1).SetText(bean.AntennaDirection4);
CT_TcPr m_Pr = table.GetRow(2).GetCell(1).GetCTTc().AddNewTcPr();
m_Pr.tcW = new CT_TblWidth();
m_Pr.tcW.w = "3500";
m_Pr.tcW.type = ST_TblWidth.dxa; //设置单元格宽度
XWPFTableRow m_Row = table.InsertNewTableRow(0);
XWPFTableCell cell = m_Row.CreateCell();
CT_Tc cttc = cell.GetCTTc();
CT_TcPr ctPr = cttc.AddNewTcPr();
ctPr.gridSpan = new CT_DecimalNumber();
ctPr.gridSpan.val = "2";
cttc.GetPList()[0].AddNewR().AddNewT().Value = "SITE 【序号】";
word_insert_space(1, m_Docx, 100);
word_insert_text(m_Docx, "宋体", 11, "SITE 【序号】勘站照片");
word_insert_text(m_Docx, "宋体", 11, "(3-10张照片)");
word_insert_space(1, m_Docx, 100);
}
示例7: Main
static void Main(string[] args)
{
XWPFDocument doc = new XWPFDocument();
XWPFTable table = doc.CreateTable(3, 3);
table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");
XWPFParagraph p1 = doc.CreateParagraph();
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);
table.GetRow(0).GetCell(0).SetParagraph(p1);
table.GetRow(2).GetCell(2).SetText("only text");
FileStream out1 = new FileStream("simpleTable.docx", FileMode.Create);
doc.Write(out1);
out1.Close();
}