在 Java 中编辑 CSV

使用用于 Java API 的服务器端 GroupDocs.Editor 进行有效且强大的 CSV 编辑,无需使用 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 中编辑 CSV 的步骤

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

  • 使用强制文件路径或字节流创建 Editor 类的实例并加载 CSV 文件
  • 为 CSV 文件格式创建 DelimitedTextEditOptions 类实例,并在构造函数中指定强制字符串分隔符
  • 调用 Editor.Edit() 方法并获得 HTML 格式的 CSV 文档,该文档可使用任何所见即所得编辑器轻松编辑。
  • 调用 Editor.Save() 方法并使用带有所需分隔符的 DelimitedTextSaveOptions 类实例保存编辑的 CSV 文件

系统要求

使用 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 CSV file into Editor with no extra loading options
Editor editor = new Editor("source.csv");

// Create edit options for delimited text and specify a mandatory separator in the constructor
DelimitedTextEditOptions editOptions = new DelimitedTextEditOptions(",");        

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

// Grab CSV 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("Cell Text", "Edited Cell Text");

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

// Create save options for delimited text and specify a mandatory separator in the constructor
DelimitedTextSaveOptions saveOptions = new DelimitedTextSaveOptions(",");

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

CSV 编辑器现场演示

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

无需下载 API

无需编写任何代码

只需上传源文件

获取下载链接以保存文件

其他支持的编辑器

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

DOC

(Microsoft Word Binary Format)

DOCX

(Office 2007+ Word Document)

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)

TSV

(Tab Seperated Values)

RTF

(Rich Text Format)

ODT

(OpenDocument Text File Format)

MSG

(Outlook Message Item File)

Back to top
 中国人