Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Interop right to left document

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?

like image 639
dubi Avatar asked Jan 04 '11 13:01

dubi


2 Answers

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;
like image 183
marg Avatar answered Oct 21 '22 07:10

marg


I would like to introduce my implementation of this feature after i used marg concept and changed it to the right syntax for me:

public void SetWorksheetDirection(Application excel, bool isRTL)
{
    Worksheet active = (Worksheet)excel.ActiveSheet;

    if (isRTL)
        excel.DefaultSheetDirection = (int)XlDirection.xlToRight;
    else
        excel.DefaultSheetDirection = (int)XlDirection.xlToLeft;

    active.DisplayRightToLeft = isRTL;
} 
like image 38
dubi Avatar answered Oct 21 '22 06:10

dubi