在 Java 中编辑 DOCX

使用用于 Java API 的服务器端 GroupDocs.Editor 进行有效且强大的 DOCX 编辑,无需使用 Microsoft 或 Open Office 等任何软件。


下载免费试用版

关于 GroupDocs.Editor for Java API

GroupDocs.Editor for Java API 是编辑 Microsoft Word、Excel、PowerPoint、Open Office 文档和演示文稿的正确选择。 GroupDocs.Editor 是一个独立的 API,适用于需要高性能的服务器端和后端系统。它不依赖于任何软件,如 Microsoft 或 Open Office。

在 Java 中编辑 DOCX 的步骤

GroupDocs.Editor for Java 为开发人员提供了一种使用几行代码编辑 DOCX 文件的简单直接的方法。

  • 使用强制文件路径或流和可选的 WordProcessingLoadOptions 类创建 Editor 类的实例并加载 DOCX 文件
  • 为 DOCX 文件格式创建和设置 WordProcessingEditOptions 类实例
  • 调用 Editor.Edit() 方法并获得 HTML 格式的 DOCX 文档,该文档可以使用任何所见即所得的编辑器轻松编辑。
  • 调用 Editor.Save() 方法并使用 WordProcessingSaveOptions 类保存编辑的 DOCX 文件

系统要求

使用 GroupDocs.Editor for Java API 进行基本文档编辑可以通过几个简单的步骤来完成。所有主要平台和操作系统都支持我们的 API。在执行以下代码之前,请确保您的系统上安装了以下先决条件。

  • 操作系统:Microsoft Windows、Linux、MacOS
  • 开发环境:NetBeans, IntelliJ IDEA, Eclipse
  • 构架: Java 7 (1.7) and above
  • 获取从 Maven 下载的最新版本 GroupDocs.Editor for Java

// Load the DOCX file into Editor with the optional WordProcessingLoadOptions
Editor editor = new Editor("source.docx", new WordProcessingLoadOptions());

// Create and adjust the edit options
WordProcessingEditOptions editOptions = new WordProcessingEditOptions();

// Open input DOCX document for edit — obtain an intermediate document, that can be edited
EditableDocument beforeEdit = editor.edit(editOptions);

// Grab DOCX document content and associated resources from editable document
string content = beforeEdit.getContent();

// Send the content to WYSIWYG-editor, edit it there, and send edited content back to the server-side
// This step simulates a such operation
string updatedContent = content.replace("Subtitle", "Edited subtitle");

// Grab edited content and resources from WYSIWYG-editor and create a new EditableDocument instance from it
EditableDocument afterEdit = EditableDocument.fromMarkup(updatedContent, null);

// Create a save options and select a desired output format
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docx);

// Save edited DOCX document to the file
editor.save(afterEdit, "edited.docx", saveOptions);

DOCX 编辑器现场演示

立即访问 GroupDocs.Editor 现场演示 网站编辑 DOCX。 现场演示有以下好处

无需下载 API

无需编写任何代码

只需上传源文件

获取下载链接以保存文件

其他支持的编辑器

您还可以编辑其他文件格式。请参阅下面的完整列表。

DOC

(Microsoft Word Binary Format)

DOCM

(Microsoft Word 2007 Marco File)

DOTX

(Microsoft Word Template File )

XLS

(Microsoft Excel Spreadsheet (Legacy))

XLSX

(Open XML Workbook)

XLSM

(Macro-enabled Spreadsheet)

PPT

(Microsoft PowerPoint 97-2003)

PPTX

(Open XML presentation Format)

PPTM

(Macro-enabled Presentation File)

MOBI

(Open Ebook Format)

EPUB

(Open eBook File)

HTML

(Hyper Text Markup Language)

MHTML

(Web Page Archive Format)

TXT

(Text Document)

XML

(XML File)

CSV

(Comma Seperated Values)

RTF

(Rich Text Format)

ODT

(OpenDocument Text File Format)

MSG

(Outlook Message Item File)

EML

(E-Mail Message)

Back to top
 中国人