'How To Chanage OpenXml Wordprocessing Text Direction?

I'm trying to open a word document and change its text direction to correct ones, here :

IEnumerable<DocumentFormat.OpenXml.Wordprocessing.Text> texts = doc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>();

foreach (DocumentFormat.OpenXml.Wordprocessing.Text text in texts)
{ -> Change text Direction <- }
doc.Save();
doc.Close();
doc.Dispose();

I have those texts, but how can I change their direction to right-to-left?



Solution 1:[1]

BiDi class set the text direction to right-to-left:

IEnumerable<DocumentFormat.OpenXml.Wordprocessing.Text> texts = doc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>();

var run = new Run(texts);
var p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph(run);
p.ParagraphProperties = new ParagraphProperties()
{
    BiDi = new BiDi(),
    TextDirection = new TextDirection()
    {
        Val = TextDirectionValues.TopToBottomRightToLeft
    }
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MD. RAKIB HASAN