Jump to content

JExcel

From Alfawiki
JExcel
Company typeSoftware library
IndustrySoftware development
DefunctMay 31, 2020 (2020-05-31)
ProductsJava API for Microsoft Excel files (.xls and .xlsx)

JExcel is a Java-based library (API) designed for reading, writing, displaying, and editing Microsoft Excel files in both .xls and .xlsx formats. It can be integrated into Java Swing and AWT applications seamlessly.

Support for JExcel was officially terminated on May 31, 2020.

Key Capabilities

The main functionalities offered by JExcel include:

  • Automating operations on Excel applications, workbooks, and sheets
  • Incorporating workbooks as components within Swing interfaces
  • Attaching event listeners and handlers to workbook and sheet events
  • Creating custom features through native peer integration

Implementation

JExcel primarily facilitates the management of Excel documents via its API.

Illustration

The following Java example illustrates how to read and update workbook properties, apply password protection, and save the file in Excel 2003 format:

<syntaxhighlight lang="Java"> import com.jniwrapper.win32.jexcel.Application; import com.jniwrapper.win32.jexcel.FileFormat; import com.jniwrapper.win32.jexcel.GenericWorkbook; import com.jniwrapper.win32.jexcel.Workbook;

import java.io.File;

public class WorkbookSample {

   public static void main(String[] args) throws Exception
   {
       Application application = new Application();
       Workbook workbook = application.createWorkbook("Custom title");
       displayWorkbookInfo(workbook);
       updateWorkbookInfo(workbook);
       File newFile = new File("Workbook.xls");
       workbook.saveAs(newFile, FileFormat.WORKBOOKNORMAL, true);
       File workbookCopy = new File("WorkbookCopy.xls");
       workbook.saveCopyAs(workbookCopy);
       workbook.close(true);
       workbook = application.openWorkbook(newFile, true, "xxx001");
       displayWorkbookInfo(workbook);
       application.close(true);
   }
   public static void displayWorkbookInfo(GenericWorkbook workbook)
   {
       System.out.println("\n[Workbook Details]");
       System.out.println("File location: " + workbook.getFile().getAbsolutePath());
       System.out.println("Name: " + workbook.getWorkbookName());
       System.out.println("Title: " + workbook.getTitle());
       System.out.println("Author: " + workbook.getAuthor());
       if (workbook.hasPassword())
           System.out.println("This workbook is password protected");
       else
           System.out.println("This workbook is not password protected");
       if (workbook.isReadOnly())
           System.out.println("Opened in read-only mode");
   }
   public static void updateWorkbookInfo(GenericWorkbook workbook)
   {
       workbook.setTitle("X-files");
       workbook.setPassword("xxx001");
       workbook.setAuthor("Agent Smith");
   }

} </syntaxhighlight>

Related Topics

External resources