Python将md批量转为docx
这两天写毕业论文, 发现了一个可以将markdown快速转为word格式的小工具pandoc, 非常好用, 比如我有一个名为
毕业论文.md
的文件, 我只需在命令行运行
pandoc 毕业论文.md -o 毕业论文.docx
即可根据md文件生成新的docx文件!
pandoc支持相互转换的格式, 多的惊人!
Pandoc主站链接
安装包下载地址
使用技巧:
- 由于word确实很难用, 我们可以用md格式书写, 然后转换成docx
- 懒是第一生产力, pandoc可以在命令行运行, 所以, 我们可以配合python脚本将
md
格式批量转换为docx
- 这是我写的一个简易脚本
import os def auto_md_to_docx(file_dir): # 获取当前目录下所有的md文件的路径信息 all_whole_path_files = [] for root, dirs, files in os.walk(file_dir): for file in files: try: if file[-3:] == ".md": file_info = [root+'/', file] all_whole_path_files.append(file_info) except Exception as e: print(e) print("==>", all_whole_path_files) # 将md依次转换为pandoc for file_info in all_whole_path_files: md_file_path_file = file_info[0] + file_info[1] docx_file_name = file_info[1][:-3] + '.docx' docx_file_path_file = file_info[0] + docx_file_name new_command = 'pandoc ' + md_file_path_file + ' -o ' + docx_file_path_file try: result = os.popen(new_command).readlines() if len(result) == 0: print(md_file_path_file, "已经转换为", docx_file_path_file) except Exception as e: print(e) def main(): auto_md_to_docx('.') if __name__ == '__main__': main()
windows用户安装pandoc
1.下载32位免安装版软件包
下载地址: https://github.com/jgm/pandoc/releases/tag/2.2.1
2.将软件包放入c盘, 并解压
3.获取pandoc.exe的绝对路径
4. 将pandoc.exe的绝对路径放入环境变量
- 值得一提的是, 我这里用的md测试文件, 都是从我的简书后台打包下载的, 也就是本地是不存在图片的, 而pandoc会自动帮我们把图片下载到本地, 然后保存到新生成的doc中.
- 只要将我的脚本稍加修改, 就可以按照上面的网状图, 进行任意两种格式的互转(比如word转pdf), 有兴趣的小伙伴可以自己动手折腾一下
另外, 小白福利, 我把这篇博客做成了视频 https://www.bilibili.com/video/av24136955/
欢迎观看, 欢迎投币, 欢迎弹幕, 欢迎转发,,,
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Jersey Java RESTful API on an Alibaba Cloud ECS Instance
By Aditya, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community. With the increased adoption of digital technology, we see that same applications are typically available across different devices, notably on laptops, mobile phones, and TV. Most of th
- 下一篇
Mavenjar包冲突的问题解决(亲测有效、实力证明)
一、今天在Pom中添加了一个依赖,导致Jar包冲突。 在启动项目的时候,会包jar包冲突的问题。下面以SpringBoot项目为例。 我在Pom.xml文件中添加了一个依赖: <dependency> <groupId>org.ethereum</groupId> <artifactId>ethereumj-core</artifactId> <version>1.6.3-RELEASE</version> </dependency> 二、在启动项目的时候就会报一个错误 Connected to the target VM, address: '127.0.0.1:57577', transport: 'socket' SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/Users/wangdong/.m2/repository/org/apache/logging/lo...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS8编译安装MySQL8.0.19
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Red5直播服务器,属于Java语言的直播服务器
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS6,CentOS7官方镜像安装Oracle11G