python - Pywin32 和 Office365
问题描述
我最近从 Office 2013 降级到 Office365,现在我的 Python 命令行脚本不再在脚本末尾退出,也不会返回任何类型的错误。我的脚本调用了我编写的帮助文件:
import pywintypes
import win32com.client as win32
def autofit(path):
excel = win32.gencache.EnsureDispatch('Excel.Application')
try:
wb = excel.Workbooks.Open(str(path))
if wb is None:
print("Excel could not open %s" % path)
return
for sh in wb.Sheets:
wb.Sheets(sh.Name).Columns.AutoFit()
wb.Save()
wb.Close(True)
except pywintypes.com_error:
print("Autofit could not open %s with Excel" % path)
excel = None
这在过去是可靠的。现在,当我在命令行上运行脚本时,它只是挂起。这个 autofit 命令是我在脚本中做的最后一件事。我已经升级到 pywin32 版本 301,问题依旧。我必须按 CTRL+BREAK 来阻止脚本运行并且文件不再获得自动调整。
这是在 Windows 10 上。
任何想法为什么这在 Excel 2013 中有效但在 365 中无效?
解决方案
推荐阅读
- forms - Vue中如何存储多个children的值并在父组件中执行一个函数
- android - 无法在 TabLayout 中将选定的选项卡居中
- flutter - 在颤动中换行
- c++ - do while循环和getline的问题-c ++
- python - 当绑定 C++ 和 Python 时,SWIG 在带有 MinGW-w64 的 Windows 上不起作用:导入时 DLL 加载失败:找不到指定的模块
- amazon-cloudformation - 用户无权在 Amazon ECS Fargate 上执行 RunTask(计划任务)
- c# - 缺少从 x 到 y 的地图。使用 CreateMap 创建
- spyder - 无法启动 spyder
- bash - 合并多个 csv 文件,其中的行按其中一列中指定的时间排序
- python - 使用python使用websocket进行计数器增量