Excel Interop right to left document

I created a new Excel file with C #.

When I open the document, all sheets are aligned from right to left.

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

+4
source share
4 answers
Sub leftToRight() Application.DefaultSheetDirection = xlLTR ActiveSheet.DisplayRightToLeft = False End Sub 

You can also change the setting using Tools-> Options-> International. Please note that you need to check / uncheck the "View current sheet from right to left" box to change the sheets currently open.

Edit: Sorry, I accidentally interpreted your question as VBA.

Here is the 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; 
+10
source

I would like to introduce my implementation of this function after I used the concept of marg and changed it to the correct 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; } 
+5
source

If you just want to organize some of the columns, you can use the following line:

 oWS.Range["A1:B2000"].HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft; 
0
source

Do this once to change the default direction:

  • Alt + F11 to open VBA editor
  • Ctrl + G to open the Immediate window
  • in the View Immediate window Application.DefaultSheetDirection = xlLTR and press Enter
  • Alt + Q to close the VBA editor
  • create a new workbook for testing.
0
source

Source: https://habr.com/ru/post/1334208/


All Articles