Edit CSV in Java

Effective and robust CSV editing using server side GroupDocs.Editor for Java APIs, without the use of any software like Microsoft or Open Office.


Download Free Trial

About GroupDocs.Editor for Java API

GroupDocs.Editor for Java API is a right choice to edit Microsoft Word, Excel, PowerPoint, Open Office documents and presentations. GroupDocs.Editor is a standalone API that is suitable for server side and back-end systems where high performance is required. It does not depend on any software like Microsoft or Open Office.

Steps to Edit CSV in Java

GroupDocs.Editor for Java provides an easy and straightforward way for developers to edit the CSV files using a few lines of code.

  • Create an instance of Editor class with mandatory file path or byte stream and load the CSV file
  • Create the DelimitedTextEditOptions class instance for the CSV file format and specify a mandatory string separator in the constructor
  • Call Editor.Edit() method and obtain CSV document in HTML format that is easily editable with any WYSIWYG-editor
  • Call Editor.Save() method and save edited CSV file using the DelimitedTextSaveOptions class instance with desired separator

System Requirements

A basic document editing with GroupDocs.Editor for Java APIs can be done by implementing a few easy steps. Our APIs are supported on all major platforms and operating systems. Before executing the code below, please make sure that you have the following prerequisites installed on your system.

  • Operating Systems: Microsoft Windows, Linux, MacOS
  • Development Environments: NetBeans, IntelliJ IDEA, Eclipse
  • Frameworks: Java 7 (1.7) and above
  • Get the latest version of GroupDocs.Editor for Java downloaded from Maven

// 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 Editor Live Demos

Edit CSV right now by visiting GroupDocs.Editor Live Demos website.
The live demo has the following benefits

No need to download API

No need to write any code

Just upload the source file

Get download link to save the file

Other Supported Editors

You can also edit other file formats. Please see the complete list below.

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
 English