彩票走势图

logo Aspose中文文档
文档彩票走势图>>Aspose中文文档>>NPOI 格式化文档中的表格

NPOI 格式化文档中的表格


Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。

Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

Aspose.Words for .NET 最新下载

Aspose.Words

请注意,在应用表属性之前,表中必须至少存在一行。这意味着使用DocumentBuilder构建表时,必须在首次调用DocumentBuilder.InsertCell之后或将第一行添加到表之后或将节点直接插入到 DOM 中时完成此类格式化。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
builder.InsertCell();

// Set the borders for the entire table.
table.SetBorders(LineStyle.Single, 2.0, Color.Black);

// Set the cell shading for this cell.
builder.CellFormat.Shading.BackgroundPatternColor = Color.DarkGray;
builder.Writeln("Cell #1");
builder.InsertCell();

// Specify a different cell shading for the second cell.
builder.CellFormat.Shading.BackgroundPatternColor=Color.Blue;
builder.Writeln("Cell #2");

// End this row.
builder.EndRow();

// Clear the cell formatting from previous operations.
builder.CellFormat.ClearFormatting();

// Create the second row.
builder.InsertCell();

// Create larger borders for the first cell of this row. This will be different
// compared to the borders set for the table.
builder.CellFormat.Borders.Left.LineWidth=4.0;
builder.CellFormat.Borders.Right.LineWidth=4.0;
builder.CellFormat.Borders.Top.LineWidth=4.0;
builder.CellFormat.Borders.Bottom.LineWidth=4.0;
builder.Writeln("Cell #3");
builder.InsertCell();

// Clear the cell formatting from the previous cell.
builder.CellFormat.ClearFormatting();
builder.Writeln("Cell #4");
doc.Save("Format Table in Document.doc");

点击复制

NPOI

// 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.IsBold=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("data/Format Table in Document.docx", FileMode.Create);
doc.Write(out1);
out1.Close();

点击复制

下载运行代码

  •  

下载示例代码

  •  
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP