JExcel is a library (API) to read, write, display, and modify Excel files with .xls or .xlsx formats. API can be embedded with Java Swing and AWT.
[2][3][4]
JExcel support is discontinued as of May 31, 2020.[5]
Some features
Some main features are as follows:
Automate Excel application, workbooks, spreadsheets, etc.
Embed workbooks in a Java Swing application as ordinary Swing component
Add event listeners to workbooks and spreadsheets
Add event handlers to handle the behavior of workbook and spreadsheet events
Add native peers to develop custom functionality.[2][3][4]
Usage
Primary usage is handling Excel files through its API.
Example
Sample code for reading/writing workbook attributes, setting password, and saving MS Excel 2003 format, might look like as follows:
importcom.jniwrapper.win32.jexcel.Application;importcom.jniwrapper.win32.jexcel.FileFormat;importcom.jniwrapper.win32.jexcel.GenericWorkbook;importcom.jniwrapper.win32.jexcel.Workbook;importjava.io.File;/** * This sample shows how to read/modify workbook attributes, how to save workbook in Excel 2003 format, * and how to reopen workbook. * * The sample works with MS Excel in non-embedded mode. */publicclassWorkbookSample{publicstaticvoidmain(String[]args)throwsException{//Start MS Excel application, crate workbook and make it visible.// Application starts invisible and without any workbooksApplicationapplication=newApplication();Workbookworkbook=application.createWorkbook("Custom title");printWorkbookAttributes(workbook);modifyWorkbookAttributes(workbook);FilenewFile=newFile("Workbook.xls");//Save workbook in Excel 2003, to save in Excel 2007 format use FileFormat.OPENXMLWORKBOOK// format specificator and *.xlsx extensionworkbook.saveAs(newFile,FileFormat.WORKBOOKNORMAL,true);FileworkbookCopy=newFile("WorkbookCopy.xls");workbook.saveCopyAs(workbookCopy);//Close workbook saving changesworkbook.close(true);//Reopening the workbookworkbook=application.openWorkbook(newFile,true,"xxx001");printWorkbookAttributes(workbook);//Perform cleanup after yourself and close the MS Excel application forcing it to quitapplication.close(true);}/** * Prints workbook attributes to console * @param workbook - workbook to print information about */publicstaticvoidprintWorkbookAttributes(GenericWorkbookworkbook){StringfileName=workbook.getFile().getAbsolutePath();Stringname=workbook.getWorkbookName();Stringtitle=workbook.getTitle();Stringauthor=workbook.getAuthor();System.out.println("\n[Workbook Information]");System.out.println("File path: "+fileName);System.out.println("Name: "+name);System.out.println("Title: "+title);System.out.println("Author: "+author);if(workbook.hasPassword()){System.out.println("The workbook is protected with a password");}else{System.out.println("The workbook is not protected with a password");}if(workbook.isReadOnly()){System.out.println("Read only mode");}}/** * Modify workbook title, author and set password * @param workbook - workbook to modify attributes */publicstaticvoidmodifyWorkbookAttributes(GenericWorkbookworkbook){workbook.setTitle("X-files");workbook.setPassword("xxx001");workbook.setAuthor("Agent Smith");}}