JExcel
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 featuresSome main features are as follows:
UsagePrimary usage is handling Excel files through its API. ExampleSample code for reading/writing workbook attributes, setting password, and saving MS Excel 2003 format, might look like as follows: 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;
/**
* 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.
*/
public class WorkbookSample
{
public static void main(String[] args) throws Exception
{
//Start MS Excel application, crate workbook and make it visible.
// Application starts invisible and without any workbooks
Application application = new Application();
Workbook workbook = application.createWorkbook("Custom title");
printWorkbookAttributes(workbook);
modifyWorkbookAttributes(workbook);
File newFile = new File("Workbook.xls");
//Save workbook in Excel 2003, to save in Excel 2007 format use FileFormat.OPENXMLWORKBOOK
// format specificator and *.xlsx extension
workbook.saveAs(newFile, FileFormat.WORKBOOKNORMAL, true);
File workbookCopy = new File("WorkbookCopy.xls");
workbook.saveCopyAs(workbookCopy);
//Close workbook saving changes
workbook.close(true);
//Reopening the workbook
workbook = application.openWorkbook(newFile, true, "xxx001");
printWorkbookAttributes(workbook);
//Perform cleanup after yourself and close the MS Excel application forcing it to quit
application.close(true);
}
/**
* Prints workbook attributes to console
* @param workbook - workbook to print information about
*/
public static void printWorkbookAttributes(GenericWorkbook workbook)
{
String fileName = workbook.getFile().getAbsolutePath();
String name = workbook.getWorkbookName();
String title = workbook.getTitle();
String author = 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
*/
public static void modifyWorkbookAttributes(GenericWorkbook workbook)
{
workbook.setTitle("X-files");
workbook.setPassword("xxx001");
workbook.setAuthor("Agent Smith");
}
}
See alsoReferences
External links
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia