如何在 Linux 上将文本文件转换为 Word 文档
问题:我想在 Linux 上准备 Microsoft Word 文档,但当然不使用任何 Microsoft 产品。有没有办法在Linux上将文本文件转换为Word文档?
如果您想在 Linux 上创建 Word 文档而不使用 Microsoft Word,一种方法当然是使用基于 Linux 的办公套件软件,例如 LibreOffice、WPS Office 或 ONLYOFFICE。这些基于 Linux 的办公套件通常提供将文档转换为 Microsoft Word 格式的选项。
如果您不想安装如此重量级的办公套件程序,另一种方法是:将内容准备在纯文本文件中,然后将文本文件转换为Word文档。
为此,您可以使用名为 pandoc
的命令行实用程序,它可以从命令行将一种标记格式转换为另一种标记格式。
在 Linux 上安装 pandoc
对于 Ubuntu、Debian 或 Linux Mint:
$ sudo apt-get install pandoc
对于费多拉:
$ sudo yum install pandoc
对于 CentOS 或 RHEL:
在 CentOS 上,首先启用 EPEL 存储库,然后使用 yum 命令。
$ sudo yum install pandoc
将文本文件转换为 Word 文档
如果要对文本文件应用任何格式,可以在文本中使用 Markdown 语法。以下是用 Markdown 语法编写的文本文件的示例。
My Title
========
Sub-title
---------
This is a new paragraph. Different paragraphs need to be separated by blank lines.
You can change the attributes of text as follows. *italic*, **bold**, `monospace`.
You can also include a [link](http://example.com). Note that there must be no space between ] and (.
This is my friend list:
* Cathy
* Julia
* Lisa
This is a numbered list:
1. Google
2. Facebook
3. Apple
You can also include an image file by using the following format.

文本文件准备好后,运行以下命令将文本文件转换为 Word 文档。
$ pandoc -o output.docx input.txt
这是生成的 Word 文档的输出。
