I’m trying to apply a specific format on an iterate excel files, i need to hide the gridlines and autofit columns width, i tried many codes and styles but no one of them worked with me.
the exported excel files shown as below PSenter image description here
JavaScript
x
12
12
1
FP_sheet=pd.read_excel(r"C:UsersMahmoud.BaderDesktopFP Attendance V1.6 Apr 22.xlsx","Attendance").fillna("")
2
FP_sheet['Date']=pd.to_datetime(FP_sheet['Date']).dt.date
3
4
5
dep = FP_sheet["Department"].unique()
6
#x=('Customer Care','Retail Customer Care','Social Media')
7
for i in dep:
8
FP_Attendance = FP_sheet[FP_sheet["Department"].str.contains(i)]
9
FP_Attendance=FP_Attendance.style.set_properties(**{'color':'black','text-align': 'center','font-family': 'Arial Narrow','border-color':'Black','border-width':'thin','border-style':'solid','vertical-align': 'middle'})
10
with pd.ExcelWriter(f"C:\Users\Mahmoud.Bader\Desktop\Python\Workforce Reports\FP Test\{i}.xlsx",engine='xlsxwriter') as writer:
11
FP_Attendance.to_excel(writer,sheet_name=str(i), index=False,freeze_panes=(1,0))
12
Advertisement
Answer
Haven’t dealt with excel formatting yet, but maybe openpyxl will offer a more friendly interface than pandas.