为“tablecell”设置RTL方向或“;Table"在OpenXml

本文关键字:Table OpenXml quot 方向 tablecell 设置 RTL | 更新日期: 2023-09-27 18:06:35

我想为我用OpenXml创建的表的某些单元格设置RTL方向。

row.Append(
    new TableCell(
        new Paragraph(
            new Run(
                new Text("FullName")))){
                    TableCellProperties = new TableCellProperties()
                    {
                        TableCellWidth = new TableCellWidth(){
                            Type = TableWidthUnitValues.Dxa,
                            Width = "3400"  },
                        TextDirection = new TextDirection(){
                            Val = new   EnumValue<TextDirectionValues>(TextDirectionValues.TopToBottomRightToLeft)}
}
});

我写了这段代码,但是TextDirectionValues Enum没有RTL值

为“tablecell”设置RTL方向或“;Table"在OpenXml

如果你的表是这样的:

TableRow > TableCell > Paragraph > Run > Text.

下面的代码可以帮助你:

//Justification
aRow.Descendants<TableCell>().ElementAt(indx).Descendants<Paragraph>()
    .ElementAt(0).ParagraphProperties = new ParagraphProperties()
    {
        Justification = new Justification()
        {
            Val = new EnumValue<JustificationValues>(JustificationValues.Right)
        }
    };
//RightToLeftText
foreach (var r in aRow.Descendants<TableCell>().ElementAt(indx).Descendants<Run>())
{
    r.RunProperties = new RunProperties()
    {
        RightToLeftText = new RightToLeftText()
        {
            Val = new OnOffValue(true)
        }
    };
}