Excel Interop right to left document

dubi picture dubi · Jan 4, 2011 · Viewed 7.7k times · Source

I created a new Excel file with C#.

When I open the document all the worksheets are align right to left.

How can I align the worksheet/workbook/window to display left to right grammatically?

Answer

marg picture marg · Jan 4, 2011
Sub leftToRight()
    Application.DefaultSheetDirection = xlLTR
    ActiveSheet.DisplayRightToLeft = False
End Sub

You can also change the setting through Tools->Options->International. Note that you need to set/unset the Checkbox "View current sheet right-to-left" to change currently open sheets.

Edit: Sorry I accidentally interpreted your question as VBA.

Here is a c# Solution:

Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
xlApp.Workbooks.Add(System.Type.Missing);  
Excel.Worksheet active = (Excel.Worksheet)xlApp.ActiveSheet;

xlApp.DefaultSheetDirection = (int)Excel.Constants.xlLTR; //or xlRTL
active.DisplayRightToLeft = false;