Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不使用openpyxl保存.xlsm的函数_Python_Excel_Openpyxl_Xlsm - Fatal编程技术网

Python 不使用openpyxl保存.xlsm的函数

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

我可以加载.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", 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] :