I am trying the following code and it is working well. But I am wondering if there is a short approach to deal with the add format feature which is there in the package of xlsxwriter. Here's the code to more clarification
import pandas as pd
import xlsxwriter
writer = pd.ExcelWriter('pandas_excel.xlsx', engine='xlsxwriter')
new_df.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
format_right_to_left = workbook.add_format()
format_right_to_left.set_reading_order(2)
myformat = workbook.add_format()
myformat.set_reading_order(2)
myformat.set_align('center')
myformat.set_align('vcenter')
worksheet = writer.sheets['Sheet1']
worksheet.right_to_left()
worksheet.set_column('B:G', 12, myformat)
worksheet.set_column('A:A', 16, myformat)
writer.save()
writer.close()
In the code I have those lines of adding format
myformat = workbook.add_format()
myformat.set_reading_order(2)
myformat.set_align('center')
myformat.set_align('vcenter')
My question how to shorten such lines so as to be more flexible and so as to be able to add more and more formats in an easy way?