登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
程序开发
>
常用工具包
&&
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
97
Star
873
Fork
243
程序员晚枫
/
python-office
代码
Issues
12
Pull Requests
0
Wiki
统计
流水线
服务
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
能增加doc转docx功能吗
待办的
#I6N3CI
突突突的芽芽
创建于
2023-03-14 18:48
我看到源码gencache.py里面用的是win32com.Dispatch()去打开文档的,那应该可以直接用来另存为docx的呀。。 ```python def doc_save_as2(file_name, ext_from, ext_to): # 获取word的打开对象 word = wc.Dispatch('Word.Application') """ 参考文档: Documents.Open 方法 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.documents.open?source=recommendations WdOpenFormat 枚举 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.wdopenformat WdSaveFormat 枚举 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.wdsaveformat """ save_ext_dict = {"xml": 11, "doc": 0, "docx": 16, "pdf": 17} open_ext_dict = {"xml": 9, "doc": 1, "docx": 1} doc = word.Documents.Open(f'{file_name}.{ext_from}', Format=open_ext_dict.get(ext_from)) new_file_name = f'{file_name}.{ext_to}' if os.path.exists(f'{file_name}.{ext_to}'): new_file_name = f'{file_name}_new.{ext_to}' doc.SaveAs(new_file_name, FileFormat=save_ext_dict.get(ext_to)) doc.Close() word.Quit() ``` 另外,能不能留一个命令是单文件转换的,有的时候不想批量转,也不想遍历子文件夹。。
我看到源码gencache.py里面用的是win32com.Dispatch()去打开文档的,那应该可以直接用来另存为docx的呀。。 ```python def doc_save_as2(file_name, ext_from, ext_to): # 获取word的打开对象 word = wc.Dispatch('Word.Application') """ 参考文档: Documents.Open 方法 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.documents.open?source=recommendations WdOpenFormat 枚举 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.wdopenformat WdSaveFormat 枚举 (Word) https://learn.microsoft.com/zh-cn/office/vba/api/word.wdsaveformat """ save_ext_dict = {"xml": 11, "doc": 0, "docx": 16, "pdf": 17} open_ext_dict = {"xml": 9, "doc": 1, "docx": 1} doc = word.Documents.Open(f'{file_name}.{ext_from}', Format=open_ext_dict.get(ext_from)) new_file_name = f'{file_name}.{ext_to}' if os.path.exists(f'{file_name}.{ext_to}'): new_file_name = f'{file_name}_new.{ext_to}' doc.SaveAs(new_file_name, FileFormat=save_ext_dict.get(ext_to)) doc.Close() word.Quit() ``` 另外,能不能留一个命令是单文件转换的,有的时候不想批量转,也不想遍历子文件夹。。
评论 (
0
)
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
Python
1
https://gitee.com/CoderWanFeng/python-office.git
git@gitee.com:CoderWanFeng/python-office.git
CoderWanFeng
python-office
python-office
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册