问题描述
我正在尝试使用python Xlwings读取Excel文件并将其写入另一个Excel文件,但是在output1.xlsx Excel文件中,如果日期值小于13,则日期和月份部分将互换。如果日期> = 13,则日期值与输入文件相同。当我检查数据框中的值时,它是正确的,并且在使用 Xlwings 将数据帧写入output1.xlsx文件时发生了问题。使用pandas.to_excel()时,会将值以正确的格式写入excel。请帮助我使用XLWINGS将数据写入数据框中以实现excel。
问题::
注意:在图片中左侧是输入数据,右侧是输出。我用红色突出显示了错误的数据,并且日期值小于13。
使用xlwings的预期输出:
代码:
import pandas as pd
import numpy as np
import xlwings as xw
df=pd.concat(pd.read_excel("input.xlsx",sheet_name=None,parse_dates=False,na_filter = False,dtype=str),ignore_index=True)
app = xw.App(visible=False)
# 1st output file using xlwings --> here the date vaues are wrong in output file output1.xlsx
book = xw.Book("output1.xlsx")
sht = book.sheets("Sheet1")
sht.range('A1').options(index=False,dates=False).value=df
book.save()
book.close()
app.quit()
# 2nd output file using pandas to_excel() -->> here the date values are correct
df.to_excel("output2.xlsx",index=False)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)