Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set text direction RightToLeft in ms word document in c#?

Tags:

c#

ms-word

I create a word document in c# with Microsoft.Office.Interop.Word

I want display my Arabic text in rtl(RightToLeft) direction. How can I set text direction to rtl ?

In my below code, I change Alighnment, But I can't change direction. Please Help me!

Word.Application wordApp = new Word.Application();
object objMissing = System.Reflection.Missing.Value;
Word.Document wordDoc = wordApp.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing);
Word.Paragraph wordParagraph = wordDoc.Paragraphs.Add(ref objMissing);
wordParagraph.Range.Font.Name = "B Titr";
wordParagraph.Range.Font.Size = 14;
WordParagraph.Range.ParagraphFormat.Alignment =  Word.WdParagraphAlignment.wdAlignParagraphRight;
wordParagraph.Range.Text = "My Arabic text";
wordParagraph.Range.InsertParagraphAfter();
like image 807
Ali Ahmadi Avatar asked Jun 28 '12 09:06

Ali Ahmadi


2 Answers

Did you try this?

wordParagraph.ReadingOrder = WdReadingOrder.wdReadingOrderRtl;
like image 156
Alexander Zbinden Avatar answered Oct 14 '22 04:10

Alexander Zbinden


Try

oDoc.Paragraphs.ReadingOrder = Word.WdReadingOrder.wdReadingOrderRtl;

where oDoc is a Word._Document instance

like image 38
Ahmad Avatar answered Oct 14 '22 04:10

Ahmad