Home > Mobile >  right to left excel page layout in python win32com
right to left excel page layout in python win32com

Time:01-13

I am using win32com for writing an excel sheet, but my data is right to left and I want to set sheet layout right to left ( same as Microsoft Excel's Page layout tab)

CodePudding user response:

https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetview.righttoleft?view=openxml-2.8.1

ActiveSheet.DisplayRightToLeft = True

edit:

To be more explicit...

import win32com.client as win32
xl = win32.gencache.EnsureDispatch('Excel.Application')

#xl.Visible = True

new_file = r'Drive:\\path\\file.xlsx'
new_book = xl.Workbooks.Open(new_file)

for sheet in new_book.Sheets: 
    xl.Worksheets(sheet.Name).Activate()
    new_book.Worksheets(sheet.Name).DisplayRightToLeft = True

xl.Application.Quit()
  •  Tags:  
  • Related