使用Novacode.DocX
.
// Create a document.
using (DocX document = DocX.Create(@"Test.docx"))
{
// Add a Table to this document.
Table t = document.AddTable(2, 3);
// Specify some properties for this Table.
t.Alignment = Alignment.center;
t.Design = TableDesign.MediumGrid1Accent2;
// Add content to this Table.
t.Rows[0].Cells[0].Paragraphs.First().Append("A");
t.Rows[0].Cells[1].Paragraphs.First().Append("B");
t.Rows[0].Cells[2].Paragraphs.First().Append("C");
t.Rows[1].Cells[0].Paragraphs.First().Append("D");
t.Rows[1].Cells[1].Paragraphs.First().Append("E");
t.Rows[1].Cells[2].Paragraphs.First().Append("F");
// Insert the Table into the document.
document.InsertTable(t);
document.Save();
}// Release this document from memory.
上面的代码将创建一个如下图所示的文档
还有,如何使用 DocX 为表格中的文本设置垂直方向?文本方向仅从右到左进行,反之亦然。
tablePlan.Rows[0].Cells[1].Paragraphs.First().Direction = Direction.LeftToRight;
以及如何从下往上放?