利用xlsxwriter对象来对Dataframe 或者 Excel对象作格式化处理:

  1. 相关案例1 相关案例2
  2. 代码:
    1. dfs = pd.read_excel('1015全市依申请政务服务指标.xls', sheet_name='汇总')
    2. writer = pd.ExcelWriter('123.xlsx', 'xlsxwriter')
    3. dfs.to_excel(writer, sheet_name='Sheet1')
    4. bookObj = writer.book
    5. writerObj = writer.book.sheetnames['Sheet1']
    6. formatObj = bookObj.add_format({'num_format': '0.00%'})
    7. writerObj.set_column('I:I', cell_format=formatObj)
    8. writerObj.set_column('J:J', cell_format=formatObj)
    9. writer.save()