Pandas ExcelWriter .xlsm文件损坏

时间:2019-12-04 10:37:49

标签: python excel pandas export corruption

在python中使用熊猫,我想使用以下代码在现有.xlsm文件上添加表格。

但是,运行过程后,我得到“我们在sample.xlsm中发现某些内容存在问题。您是否要我们尝试尽可能多地恢复?如果您信任此工作簿的来源,请单击“是”。警告。

我该如何解决此问题?谢谢。

import pandas as pd
import numpy as np
from openpyxl import load_workbook
import copy
import time

dfTRYprod = pd.readexcel('sample2.xlsm', sheetname='TRY Products', usecols ="A:AZ", nrows=100, indexcol = 0)
book = loadworkbook(sample.xlsm, readonly=False, keep_vba=True)

options = {}
options['stringstoformulas'] = False
options['stringstourls'] = False

writer=pd.ExcelWriter (paths, engine= 'openpyxl',options=options)
writer.book = book

del book['TRY Products']

dfTRYprod.toexcel(writer, sheet_name='TRY Products')

writer.save()
writer.close()

0 个答案:

没有答案