Python openpyxl 如何绕过写入打开文件的权限

Python openpyxl How to bypass permissions to write to an open file

我正在尝试编写一个脚本来实时编辑打开的 excel 文件,但是当我尝试 运行 使用 openpyxl 并从单元格读取然后将数据写回该单元格的脚本时有编辑的单元格,它给出了这个错误 PermissionError: [Errno 13] Permission denied: 'GameExcel.xlsx' 有没有办法使用另一个模块解决这个问题,或者我是否遗漏了一个秘密

编辑这里的代码,这也是我在将其集成到完整代码之前的学习。

import openpyxl
from openpyxl import load_workbook
from openpyxl import workbook
from openpyxl.utils import get_column_letter
import os
import tkinter as tk
from tkinter import messagebox as tkMsgBox
import time

os.chdir("D:\Scripts\Python\Testing Scripts\My Excel Game")
wb = load_workbook("GameExcel.xlsx")
names = wb.sheetnames
sheet = wb['GameEnviroment']

#userInput = (input("what would you like it to say?"))
#print(userInput)
C3Val = sheet['C4'].value

sheet.cell(row=3, column=4).value = (C3Val + ' 4')
wb.save('GameExcel.xlsx')
print(C3Val + ' 3')
#sheet['A1']=userInput

这是由于操作系统的限制(即Windows)。它与openpyxl、Python甚至Excel都没有关系。 POSIX based OS do not have such a limitation.

这个问题 ("How to bypass permissions to write to an open file") 的答案很简单 "You can't"。

我使用的选项是 xlwings

,它只适用于 excel 打开