I am trying to get the following output. All rows and columns are text wrapped except the header though:
import pandas as pd
import pandas.io.formats.style
import os
from pandas import ExcelWriter
import numpy as np
from xlsxwriter.utility import xl_rowcol_to_cell
writer = pd.ExcelWriter('test1.xlsx',engine='xlsxwriter',options={'strings_to_numbers': True},date_format='mmmm dd yyyy')
df = pd.read_csv("D:\\Users\\u700216\\Desktop\\Reports\\CD_Counts.csv")
df.to_excel(writer,sheet_name='Sheet1',startrow=1 , startcol=1, header=True, index=False, encoding='utf8')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
format = workbook.add_format()
format1 = workbook.add_format({'bold': True, 'align' : 'left'})
format.set_align('Center')
format1.set_align('Center')
format.set_text_wrap()
format1.set_text_wrap()
worksheet.set_row(0, 20, format1)
worksheet.set_column('A:Z', 30, format)
writer.save()
format is applied for all rows and columns except header. i dont know why format is not applied to first column (Header) or i would like to manually add column header numbers such as 0,1,2 etc so that i will turn of the header therefore all the rows and columns will be formatted
In the above screenshot wrap text is not applied to A1 to E1, C1 column has header with lot of space. if i manually click wrap text it gets aligned else all the header is not formatted using text wrap.