0

Why the following code can't format 44000 to a date in excel? It shows up in xls file as the original number no matter what I try.

Things I have tried:

  • Different format string, none works. I copy them from source file so no mistake here
  • Check style object with breakpoint, it gets the correct num_format_str
  • quote or un-quote the number

I am using Mac Preview to open the xls file if that's relevant.

    import xlwt

    book = xlwt.Workbook(encoding='utf8')
    sheet = book.add_sheet('sheet 1')        
    style = xlwt.easyxf(num_format_str="M/D/YY") 
    sheet.write(1, 1, 44000, style=style)

    response = HttpResponse(mimetype='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename=test.xls'
    book.save(response)
    return response
4

1 回答 1

0

代码没有问题。问题出在 Mac Preview 上。我在 Windows 上的 Excel 中打开文件并44400显示为日期。

于 2013-06-17T04:19:18.490 回答