title: autofit column width using xlswriter || Django
body: <p>I am generating excel in my Django <strong>views.py</strong> but since column names are a bit long, I am <strong>having a hard time to set auto column fit width manually every time</strong> I/user downloads the excel.</p>
  
  <p>Below is my working code snippet for excel generation using xlswriter.</p>
  
  <pre><code>def excel(request):
      ans = request.POST.getlist('ans[]')
      ans_final=[]
      rows = request.POST.get('rows')
      for each_ele in ans:
          each_ele = each_ele.split('.')
          each_ele[0] = each_ele[0][:-2]
          each_ele[1] = each_ele[1][:-2]
      fin = each_ele[0]+' - '+each_ele[1]
      ans_final.append(fin)
      workbook = xlsxwriter.Workbook('/home/Desktop/status.xlsx')
      worksheet = workbook.add_worksheet('Test_Data')
      bold = workbook.add_format({'bold': True})
      for i in range(len(ans_final)):
          worksheet.write(0, i,ans_final[i],bold)
  
      row_index=1
      row_count = int(rows)
      while(row_count):
          col_index=0
          for each_ele in ans:
              worksheet.write(row_index, col_index, eval(each_ele))
              col_index += 1
          row_index += 1
          row_count -= 1
  
  
     workbook.close() 
     return JsonResponse({'ok':'ok'})
  </code></pre>
  
  <p>Please suggest a work around for setting <strong>Auto-fit column width</strong> in the above code.</p>