Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 813
Farzad Karimi Avatar asked Oct 17 '25 06:10

Farzad Karimi


1 Answers

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
    }
};
like image 147
MD. RAKIB HASAN Avatar answered Oct 19 '25 21:10

MD. RAKIB HASAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!