3

我正在尝试使用Python为我的 excel 文档创建一个定时备份系统,因为多个用户将访问它。我想将文件的路径更改为我的本地目录。

这是代码;

import pandas as pd
import datetime
import numpy
now = datetime.datetime.now()
ct = now.strftime("%Y-%m-%d %H.%M")

table = pd.read_excel(r'Z:\new\Planner_New.xlsx',
                  sheet_name = 'Jan18',                
                  header = 0,
                  index_col = 0,
                  usecols = "A:AY",
                  convert_float = True)

writer = pd.ExcelWriter('Planner' + ct + '.xlsx', engine='xlsxwriter')
table.to_excel(writer, sheet_name = "Jan18")

workbook  = writer.book
worksheet = writer.sheets['Jan18']

format1 = workbook.add_format({'num_format': '0%'})
worksheet.set_column('H:AY', None, format1)

writer.save()
writer.close()

我努力了

outpath = (r'Z:\backup')
writer.save(outpath)
writer.close()

但是回来

类型错误:save() 接受 1 个位置参数,但给出了 2 个

4

1 回答 1

2

ExcelWriter创建对象时需要指定保存位置:

writer = pd.ExcelWriter(r'Z:\backup\Planner' + ct + '.xlsx', engine='xlsxwriter')

...

writer.save()
writer.close()
于 2018-04-27T09:27:24.353 回答