使用xlwt将数据写入新工作簿时,默认情况下,日期列更改为数字列。需要保留日期格式
尝试使用datetime函数,但是我混合了所有列,其中只有一个是日期列
from xlrd import open_workbook
from xlwt import Workbook
import os
for file in os.listdir('C:\\Users\chidambs\Documents\Shiva\\'):
if file.endswith(".xlsx"):
rb = open_workbook('C:\\Users\chidambs\Documents\Shiva\\'+ str(file),formatting_info=False)
num = rb.nsheets
for a in range(num):
rs = rb.sheet_by_index(a)
sheet = (rs.name)
new_book = Workbook()
new_sheet = new_book.add_sheet(sheet)
for row in range(rs.nrows):
for col in range(rs.ncols):
new_sheet.write(row, col, rs.cell(row, col).value)
new_book.save("C:\\Users\chidambs\Documents\Shiva\\" + str(sheet) + ".xls")
预期: 周末收场B B Col C ......... 3/23/2019 3/23/2019 3/23/2019 3/23/2019 3/23/2019 3/23/2019
实际: 周末收场B B Col C ......... 43547 43547 43547 43547 43547