Updating spreadsheet data programmatically is a frequent requirement for Java developers who need to generate reports, modify templates, or integrate Excel files into business workflows. Conholdate.Total for Java provides a robust SDK that makes it easy to update Excel CELL value in Java with just a few lines of code. In this guide you will learn how to load a workbook, change specific cells, apply numeric formatting, and save the updated file.
Steps to Update Excel CELL Value in Java
Load the workbook with memory optimization: Create a
LoadOptionsinstance, enable memory optimization, and pass it to theWorkbookconstructor.LoadOptions loadOptions = new LoadOptions(); loadOptions.setEnableMemoryOptimization(true); Workbook workbook = new Workbook("input.xlsx", loadOptions);Access the target worksheet: Retrieve the first worksheet (index 0) from the workbook.
Worksheet worksheet = workbook.getWorksheets().get(0);Locate the cell to update: Use zero‑based row and column indexes to get cell B2 (row 1, column 1). Then call
setValueto update Excel CELL value in Java.Cell cell = worksheet.getCells().get(1, 1); cell.setValue("Updated Value");Apply optional formatting: For numeric cells you can set the data type and number format, as shown in the example for cell C3.
Cell numericCell = worksheet.getCells().get(2, 2); numericCell.setValue(12345.678); numericCell.setDataType(DataType.NUMERIC); Style style = numericCell.getStyle(); style.setNumberFormat("#,##0.00"); numericCell.setStyle(style);Save the workbook: Create a
SaveOptionsobject and callsavewith the desired output path.SaveOptions saveOptions = new SaveOptions(); workbook.save("output.xlsx", saveOptions);
Update Excel CELL Value in Java - Complete Code Example
The following code shows the full implementation of updating an Excel cell, applying numeric formatting, and saving the result.
import com.groupdocs.total.excel.Workbook;
import com.groupdocs.total.excel.Worksheet;
import com.groupdocs.total.excel.Cell;
import com.groupdocs.total.excel.LoadOptions;
import com.groupdocs.total.excel.SaveOptions;
import com.groupdocs.total.excel.Style;
import com.groupdocs.total.excel.DataType;
import java.io.IOException;
public class UpdateExcelCell {
public static void main(String[] args) {
String inputPath = "input.xlsx";
String outputPath = "output.xlsx";
// Load options can be tuned for large worksheets (e.g., enable memory optimization)
LoadOptions loadOptions = new LoadOptions();
loadOptions.setEnableMemoryOptimization(true);
Workbook workbook = null;
try {
// Load the workbook
workbook = new Workbook(inputPath, loadOptions);
// Access the first worksheet (index 0)
Worksheet worksheet = workbook.getWorksheets().get(0);
// Update cell B2 (row index 1, column index 1 – zero based)
Cell cell = worksheet.getCells().get(1, 1);
cell.setValue("Updated Value");
// Example: set numeric format and data type for another cell (C3)
Cell numericCell = worksheet.getCells().get(2, 2);
numericCell.setValue(12345.678);
numericCell.setDataType(DataType.NUMERIC);
Style style = numericCell.getStyle();
style.setNumberFormat("#,##0.00");
numericCell.setStyle(style);
// Save the workbook with default save options
SaveOptions saveOptions = new SaveOptions();
workbook.save(outputPath, saveOptions);
} catch (IOException e) {
System.err.println("I/O error while processing the Excel file: " + e.getMessage());
} catch (Exception e) {
System.err.println("Unexpected error: " + e.getMessage());
} finally {
// Ensure resources are released
if (workbook != null) {
try {
workbook.dispose();
} catch (Exception e) {
System.err.println("Error while disposing workbook: " + e.getMessage());
}
}
}
}
}
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, 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.
Conholdate.Total for Java - Prerequisites and Setup
Add the Conholdate Maven repository and the SDK dependency to your pom.xml. Then download the latest library from the official site.
<repositories>
<repository>
<id>conholdate-repo</id>
<name>Conholdate Maven Repository</name>
<url>https://repository.conholdate.com/repo/</url>
</repository>
</repositories>
<dependency>
<groupId>com.conholdate</groupId>
<artifactId>conholdate-total</artifactId>
<version>24.9</version>
<type>pom</type>
</dependency>
Download the SDK package from the download page and ensure you are running Java 8 or higher.
Conholdate.Total for Java Capabilities for Excel Editing
- Load and save XLSX, XLS, CSV - The SDK reads and writes all common spreadsheet formats without data loss.
- Cell‑level manipulation - Access any cell by row and column indexes, update its value, and change its data type.
- Styling and number formats - Apply
Styleobjects to set number formats, fonts, colors, and borders directly on cells. - Memory‑optimized processing -
LoadOptions.setEnableMemoryOptimization(true)helps work with large worksheets efficiently. - Comprehensive API reference - Detailed class documentation is available in the API reference.
Configuring Excel Cell Update Options
You can fine‑tune how the SDK handles large files and formatting:
- Memory optimization - Enable it via
LoadOptions.setEnableMemoryOptimization(true)(shown in the code). - Save options - Use
SaveOptionsto control output format, compression, and whether to keep original formulas. - Data type control - Set
DataType.NUMERICfor numbers,DataType.STRINGfor text, etc., to ensure correct cell behavior.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setEnableMemoryOptimization(true);
Frequently Asked Questions
Can I update multiple cells with Conholdate.Total for Java?
Yes, you can call the same cell‑update logic repeatedly to update many cells in a worksheet. The SDK lets you locate each cell and use the same setValue method to update Excel CELL values in Java.
What Excel formats are supported for cell updates?
Conholdate.Total for Java works with XLSX, XLS, CSV and other spreadsheet formats. You can load any supported workbook, modify cells, and save back to the original or a different format.
How do I obtain a temporary license for Conholdate.Total for Java?
A temporary license can be requested from the temporary license page. For full production use, see the pricing page to choose a suitable plan.
Where can I find more examples and community help?
The official documentation provides detailed API references, and the support forum is a great place to ask questions.
