[]
        
(Showing Draft Content)

Saving and Export Excel XLSX Files Using Java

This tutorial shows how to persist generated or modified Excel workbooks using Document Solutions for Excel, Java Edition (DsExcel Java). You’ll learn how to create a minimal workbook in memory and save it as a standard .xlsx file using the Workbook.save() method.


Prerequisites

Before you begin, make sure you have:

  • JDK 8 or later

  • Document Solutions for Excel, Java Edition (DsExcel Java)

  • The DsExcel JARs added to your classpath

Import the required namespaces:

import com.grapecity.documents.excel.*;

1) Create a Minimal Excel Workbook in Java

Start by creating a new Workbook object and getting the first worksheet:

Workbook workbook = new Workbook();
IWorksheet worksheet = workbook.getWorksheets().get(0);
worksheet.setName("Sheet1");

(Optional) Add a little data so you can verify output:

worksheet.getRange("A1").setValue("Hello from DsExcel Java!");
worksheet.getRange("A2").setValue(12345);

2) Save the Workbook as an XLSX File

To export the workbook, call Workbook.save() from your workbook object with a file name or full path.

Save to the current working directory

workbook.save("output.xlsx");

Save to an absolute file path (Windows)

Be sure to replace "temp" with the file path to where you are trying to save the file.

workbook.save("C:\\temp\\output.xlsx");

Save to an absolute file path (Linux/macOS)

workbook.save("/tmp/output.xlsx");

Notes for Server-Side Usage

DsExcel Java is designed to run server-side and does not require Microsoft Excel or Office Interop.

Common server-side usage patterns include:

  • Generating Excel reports in a REST API

  • Updating uploaded .xlsx templates and exporting a final version

  • Running automated scheduled exports on Linux servers


Next Steps