gpt4 book ai didi

c# - 如何使用 Novacode DocX 在代码中为表格中的文本设置垂直方向?

转载 作者:可可西里 更新时间:2023-11-01 10:45:33 28 4
gpt4 key购买 nike

使用 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;

以及如何从下往上放?

enter image description here

最佳答案

您可以通过添加:

t.Rows[0].Cells[0].TextDirection = TextDirection.btLr;
t.Rows[0].Cells[1].TextDirection = TextDirection.btLr;
t.Rows[0].Cells[2].TextDirection = TextDirection.btLr;

关于c# - 如何使用 Novacode DocX 在代码中为表格中的文本设置垂直方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27653565/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com