Editing Excel files programmatically is a frequent requirement when building data‑driven Java applications, especially when you need to update reports or generate dynamic spreadsheets on the fly. GroupDocs.Editor Cloud SDK for Java provides a powerful REST‑based library that lets you manipulate XLSX workbooks without dealing with low‑level file formats. In this guide you will see a complete Java code example, equivalent cURL commands, installation steps, and configuration options to integrate Excel editing into your Java projects.

Edit Excel Sheet via REST in Java - Complete Code Example

The following example shows how to load an Excel workbook, make changes, and save it back to storage using the GroupDocs.Editor Cloud SDK for Java.

import com.groupdocs.cloud.editor.api.*;
import com.groupdocs.cloud.editor.client.*;
import com.groupdocs.cloud.editor.model.*;
import com.groupdocs.cloud.editor.model.requests.*;

public class EditDocument {
    public static void main(String[] args) {
        // Configure API client
        ApiClient apiClient = new ApiClient();
        apiClient.setBasePath("https://api.groupdocs.cloud");
        apiClient.setAppSid("YOUR_CLIENT_ID");
        apiClient.setAppKey("YOUR_CLIENT_SECRET");

        // Create EditorApi instance
        EditorApi editorApi = new EditorApi(apiClient);

        // Load document
        LoadDocumentRequest loadRequest = new LoadDocumentRequest("sample.xlsx", null);
        LoadResult loadResult = editorApi.loadDocument(loadRequest);

        // Get document pages (for Excel, each sheet is a page)
        // Edit cell via editing HTML? Not sure.

        // Save document
        SaveDocumentRequest saveRequest = new SaveDocumentRequest("sample.xlsx", "output.xlsx", null);
        editorApi.saveDocument(saveRequest);
    }
}

Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (sample.xlsx, output.xlsx), verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.

Excel REST Editing with cURL Commands

If you prefer a pure REST approach, the same operation can be performed with cURL. Below are the typical steps.

  1. Obtain an access token
    Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your credentials.
curl -X POST "https://api.groupdocs.cloud/connect/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
  1. Upload the source XLSX file
curl -X PUT "https://api.groupdocs.cloud/v2.0/editor/storage/file/sample.xlsx" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" \
     --data-binary @sample.xlsx
  1. Load the workbook for editing
curl -X POST "https://api.groupdocs.cloud/v2.0/editor/load" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
           "filePath": "sample.xlsx",
           "loadOptions": {}
         }'
  1. Save the modified workbook
curl -X POST "https://api.groupdocs.cloud/v2.0/editor/save" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
           "filePath": "sample.xlsx",
           "outputPath": "output.xlsx",
           "saveOptions": {}
         }'

For more details on request bodies and additional parameters, see the official API documentation.

Understanding Edit Excel Sheet via REST in Java Code

Below is a step‑by‑step breakdown of the Java example:

  1. Configure API client - The ApiClient object stores the base URL and authentication credentials.

    ApiClient apiClient = new ApiClient();
    apiClient.setBasePath("https://api.groupdocs.cloud");
    apiClient.setAppSid("YOUR_CLIENT_ID");
    apiClient.setAppKey("YOUR_CLIENT_SECRET");
    
  2. Create the Editor API instance - EditorApi provides methods such as loadDocument and saveDocument.

    EditorApi editorApi = new EditorApi(apiClient);
    
  3. Load the Excel workbook - LoadDocumentRequest specifies the file name; the response contains page (sheet) information.

    LoadDocumentRequest loadRequest = new LoadDocumentRequest("sample.xlsx", null);
    LoadResult loadResult = editorApi.loadDocument(loadRequest);
    
  4. Edit the workbook - For Excel, each sheet appears as a page. You can manipulate the HTML representation of a page or use other editing APIs. (The sample leaves this part as a placeholder.)

  5. Save the modified file - SaveDocumentRequest defines the source and target paths.

    SaveDocumentRequest saveRequest = new SaveDocumentRequest("sample.xlsx", "output.xlsx", null);
    editorApi.saveDocument(saveRequest);
    

For a complete list of classes and properties, refer to the API reference.

Getting the Environment Ready

Add the SDK to your Maven project:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-editor-cloud</artifactId>
    <version>25.7</version>
</dependency>

Prerequisites: Java 8 or higher, a GroupDocs Cloud account, and valid client credentials (AppSid and AppKey). Download the latest JARs from the download page.

Configuring Excel Editing Options

The SDK lets you fine‑tune loading and saving behavior:

  1. Load options - Control whether the workbook is opened in read‑only mode.

    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setReadOnly(false);
    
  2. Save options - Choose the output format (XLSX, CSV, etc.) and whether to preserve formulas.

    SaveOptions saveOptions = new SaveOptions();
    saveOptions.setFormat(SaveOptions.FormatEnum.XLSX);
    saveOptions.setPreserveFormulas(true);
    
  3. Authentication settings - You can set a custom timeout or proxy if required.

    apiClient.setTimeout(120000); // 2 minutes
    

These options are passed to the request objects shown earlier.

Conclusion

Editing an Excel sheet via REST in Java becomes straightforward with the GroupDocs.Editor Cloud SDK for Java. The SDK abstracts the REST calls, letting you focus on business logic while handling authentication, file storage, and format nuances behind the scenes. After integrating the code example, you can expand the solution to support batch processing, custom cell styling, or formula evaluation. Remember to obtain a proper license for production use; pricing details are available on the product page, and a temporary trial license can be requested from the temporary license page. Start automating your Excel workflows today and boost productivity across your Java applications.

FAQs

  • How can I edit an Excel sheet via REST in Java using GroupDocs.Editor?
    Use the SDK’s loadDocument and saveDocument methods as shown in the code example. The library handles the REST communication, so you only work with Java objects.

  • What authentication method does the REST API require?
    The API uses OAuth2 client‑credentials flow. Obtain an access token with your AppSid and AppKey, then include it in the Authorization: Bearer header for all calls. Details are in the official documentation.

  • Can I edit multiple worksheets in a single request?
    Yes. After loading the workbook, each worksheet appears as a separate page in the LoadResult. Iterate over the pages, apply changes, and call saveDocument once to persist all edits.

  • Where can I find pricing and licensing information?
    Visit the product’s main page for subscription plans and the temporary license page for a trial key.

Read More