title: Using xlrd to read dates and xlsxwriter to write them in Python
body: <p>I am using xlrd to read a bunch of raw data from an excel spreadsheet, do various calculations and reformatting, and then write my results to a new workbook using xlsxwriter. </p>
  
  <p>I'm able to read in the date data correctly using xlrd and convert to a datetime object, but when I try to write this using xlsxwriter I get errors. I've read all the SO posts on xlsxwriter and how excel formats data, etc., and googled it, but can't seem to figure it out.</p>
  
  <p>My code is: </p>
  
  <pre><code>in_wb = xlrd.open_workbook("in_book.xlsx")
  in_sheet = in_wb.sheet_by_name("in_sheet")
  
  out_wb = xlsxwriter.Workbook("out_book.xlsx")
  out_sheet = out_wb.add_worksheet("out_sheet")
  date_format = out_wb.add_format({'num_format': 'YYYY-MM-DD HH:DD:SS'})
  
  as_tuple = xlrd.xldate_as_tuple(in_sheet.cell_value(0, 0), in_wb.datemode)
  as_datetime = datetime.datetime(as_tuple[0], as_tuple[1], as_tuple[2] , as_tuple[3], as_tuple[4], as_tuple[5])
  
  out_sheet.write_datetime(0, 0, as_datetime, date_format)
  
  #print details just to be sure
  print as_datetime #prints it in exactly the format I want
  print type(as_datetime) #says it is of type 'datetime.datetime'
  </code></pre>
  
  <p>The full Traceback error is (excluding the very first call from my py file):</p>
  
  <pre><code>  File "C:\Python27\lib\site-packages\xlsxwriter\worksheet.py", line 57, in cell_wrapper
  return method(self, *args, **kwargs)
    File "C:\Python27\lib\site-packages\xlsxwriter\worksheet.py", line 668, in write_datetime
  number = self._convert_date_time(date)
    File "C:\Python27\lib\site-packages\xlsxwriter\worksheet.py", line 3267, in _convert_date_time
  return datetime_to_excel_datetime(dt_obj, self.date_1904)
    File "C:\Python27\lib\site-packages\xlsxwriter\utility.py", line 576, in datetime_to_excel_datetime
  raise TypeError("Unknown or unsupported datetime type")
    TypeError: Unknown or unsupported datetime type
    Exception LookupError: 'unknown encoding: utf-8' in &lt;bound method Workbook.__del__ of &lt;xlsxwriter.workbook.Workbook object at 0x030BAB50&gt;&gt; ignored
  </code></pre>
  
  <p>When I call just the ordinary 'out_sheet.write' instead, the resulting spreadsheet shows a bunch of '######' in the cell, but when I click on the cell it shows the date and time as I wanted it, not sure how to get ride of these '####' when I do it this way. I don't care about using write_datetime() or just write(), I just want it to show up correctly in the output sheet cells. </p>
  
  <p>Thanks very much for your help!</p>