开发者

Set RTL direction for "Tablecell" or "Table" in OpenXml

开发者 https://www.devze.com 2023-03-30 03:11 出处:网络
I want to set a RTL direction for some cell of a table that I create with OpenXml. row.Append( new TableCell(

I want to set a RTL direction for some cell of a table that I create with OpenXml.

row.Append(
    new TableCell(
        new Paragraph(
            new Run(
                new Text("FullName")))){
                    TableCellProperties = new TableCellProperties()
                    {
                        TableCellWidth = new TableCellWidth(){
                            Type = TableWidthUnitValues.Dxa,
                            Width = "3400"  },
                        TextDirection = new TextDirec开发者_C百科tion(){
                            Val = new   EnumValue<TextDirectionValues>(TextDirectionValues.TopToBottomRightToLeft)}
}
});

I wrote this code, but TextDirectionValues Enum dosen't have a RTL value.


If your tables are like this:

TableRow > TableCell > Paragraph > Run > Text.

This code may help you:

//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)
        }
    };
}
0

精彩评论

暂无评论...
验证码 换一张
取 消