Python 不使用openpyxl保存.xlsm的函数
我可以加载.xlsm并另存为.xlsm,但它无法正确保存函数。[original][1]excel文件函数来自excel库存函数。运行python之后的一个是[here][2] 这是我的密码Python 不使用openpyxl保存.xlsm的函数,python,excel,openpyxl,xlsm,Python,Excel,Openpyxl,Xlsm,我可以加载.xlsm并另存为.xlsm,但它无法正确保存函数。[original][1]excel文件函数来自excel库存函数。运行python之后的一个是[here][2] 这是我的密码 import openpyxl import math import numpy # load excel file print("Start Loading data.") wb = openpyxl.load_workbook(filename = r"file.xlsm
import openpyxl
import math
import numpy
# load excel file
print("Start Loading data.")
wb = openpyxl.load_workbook(filename = r"file.xlsm", data_only = True, keep_vba=True)
print("finished Loading data.")
# loop though all sheets
for sheet in wb:
# make sure it is not the first sheet
if sheet.title != 'SNP500':
print(sheet)
cells = []
for row in sheet.iter_rows(min_row = 2, min_col = 2, values_only=True):
cells.append(row[0])
movingAvg = []
# calculate the moving average
for i in range(50, len(cells)):
c = sheet.cell(row = i, column = 3)
c.value = round(numpy.average(cells[i - 50: i]),3)
if sheet.title == 'A':
break
wb.save(r"file.xlsm")
我不知道我做错了什么。任何帮助都将不胜感激。非常感谢。
[1]:
[2] :