导出日期时间Excel Python

问题描述

无法导出日期。

import xlwt
from tempfile import TemporaryFile
book = xlwt.Workbook()
sheet1 = book.add_sheet('sheet1')
cur.execute('SELECT date,name from table')
rows = cur.fetchall()
for row,array in enumerate(rows):
    for col,value in enumerate(array):
        sheet1.write(row,col,value)

name = "this.xls"
book.save(name)
book.save(TemporaryFile())

它给出的是44044,而不是08/17/2020。

解决方法

select coalesce((SELECT rowID FROM dbo.column1 where c.rowID = '1234-1234-1234' and LocaleID = @LanguageCode),(SELECT rowID FROM dbo.column1 where c.rowID = '1234-1234-1234' and LocaleID = 'ENU')); 在Excel中是44044

44044是从0.0.1900到2020/8/17的日子。

您需要将Excel中的格式从数字更改为日期,它会显示正确的日期。

08/17/2020

如果仍然遇到麻烦,请尝试将date_format = xlwt.XFStyle() date_format.num_format_str = 'dd/mm/yyyy' sheet1.write(row,col,value,date_format) 替换为这样的日期时间:

value

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...