title: Formatting multiple worksheets using xlsxwriter
body: <p>How to copy the same formatting to different sheets of the same Excel file using the <code>xlsxwriter</code> library in Python?</p>
  
  <p>The code I tried is: </p>
  
  <pre><code>import xlsxwriter
  
  import pandas as pd
  import numpy as np
  
  from xlsxwriter.utility import xl_rowcol_to_cell
  
  df = pd.DataFrame()
  df = pd.read_excel('TrendAnalysis.xlsx')
  
  
  
  # Create a Pandas Excel writer using XlsxWriter as the engine.
  # Save the unformatted results
  writer_orig = pd.ExcelWriter('TrendAnalysis.xlsx', engine='xlsxwriter')
  df.to_excel(writer_orig, index=True)
  writer_orig.save()
  
  work = ["isu-wise", "ISU-BFS", "ISU-CPG", "ISU-ER", "ISU-GE", "ISU-GOV Domestic", "ISU-GOV Overseas", "ISU-HC"]
  # Create a Pandas Excel writer using XlsxWriter as the engine.
  writer = pd.ExcelWriter('TrendAnalysis.xlsx', engine='xlsxwriter')
  for i in range(0,len(work)):
      df.to_excel(writer, index=True, sheet_name=work[i])
  
      # Get access to the workbook and sheet
      workbook = writer.book
      worksheet = writer.sheets[work[i]]
  
      print worksheet
      # We need the number of rows in order to place the totals
      number_rows = len(df.index)
  
      # Total formatting
      total_fmt = workbook.add_format({'align': 'right', 'num_format': '#,##0',
                                      'bold': True, 'bottom':6})
  
      # Add total rows
      for column in range(1,3):
          # Determine where we will place the formula
          cell_location = xl_rowcol_to_cell(number_rows+1, column)
          # Get the range to use for the sum formula
          start_range = xl_rowcol_to_cell(1, column)
          end_range = xl_rowcol_to_cell(number_rows, column)
          # Construct and write the formula
          formula = "=SUM({:s}:{:s})".format(start_range, end_range)
          worksheet.write_formula(cell_location, formula, total_fmt)
  
      # Add a total label
      worksheet.write_string(number_rows+1, 0, "Total",total_fmt)
      i+=1
  
  writer.save()
  workbook.close()
  </code></pre>
  
  <p>It creates the same sheet multiple times. Doesn't navigate and the sheets after the first one of the workbook. The code is error free and does the required formatting otherwise.</p>