我正在将现有文件复制到新工作簿中,然后隐藏一些不必要的选项卡。需要可见的选项卡之一包含一个数据透视表,该数据透视表在脚本完成后显示为值(而不是实际的数据透视表)。我需要“保留”数据透视表
编辑:Excel 2013版本
这是我的代码:
import xlsxwriter
import openpyxl as xl
import shutil
shutil.copy('C:/Prueba/GOOG.xlsm', 'C:/Prueba/GOOG-copia.xlsm')
workbook = xl.load_workbook('C:/Prueba/GOOG-copia.xlsm', keep_vba = 'True')
keep = ['Cacaca','Sheet1'] # Cacaca contains a pivot table that needs to be preserved
for i in workbook.sheetnames:
if i in keep:
pivot = workbook[i]._pivots[0]
pivot.cache.refreshOnLoad = True
workbook[i].sheet_state = 'visible'
else:
workbook[i].sheet_state = 'hidden'
workbook.save('C:/Prueba/GOOG-copia.xlsm')
workbook.close
错误:
AttributeError: 'Worksheet' object has no attribute '_pivots'
眼眸繁星
相关分类