API Reference:
Http://www.andykhan.com/jexcelapi/index.html
Website:
http://jexcelapi.sourceforge.net/
1. Create a writable workbook workbook
Writableworkbook workbook = Workbook.createworkbook (new File ("C:\Test.xls"));
2. Read the existing workbook workbook (not writable)
Workbook Workbook = Workbook.getworkbook (new File ("C:\template.xls"));
3. Create a writable sheet
Workbook.createsheet ("name", 0);
4. Read the existing sheet
Workbook.getsheet (0);
5. Create a label
New Label (0,0, "content");
6. Add a label to the sheet
Sheet.addcell (label);
7. Create workbook based on template
Workbook template = Workbook.getworkbook (new File ("C:\template.xls"= Workbook.createworkbook ( New File ("C:\Test.xls"), template);
8. Example of creating Excel
Writableworkbook workbook = Workbook.createworkbook (new File ("C:\Test.xls"= Workbook.getsheet (0 New label (0,0, "content"new label (0,1, "content"); Sheet.addcell (Label1); Sheet.addcell (Label2); Workbook.write (); Workbook.close ();
9. Example of creating Excel from a template
Workbook template = Workbook.getworkbook (new File ("C:\template.xls"= Workbook.createworkbook ( New File ("C:\Test.xls"= Workbook.getsheet (0new Label (0,0, "content" New Label (0,1, "content"); Sheet.addcell (Label1); Sheet.addcell (Label2); Workbook.write (); Workbook.close () ;
10. Formatting using template cells
Workbook template = Workbook.getworkbook (new File ("C:\template.xls"= Workbook.createworkbook ( New File ("C:\Test.xls"= workbook.getsheet (0); // get the format of a template cell (font, color, etc.) CellFormat CellFormat = Sheet.getwritablecell (0, 0new Label (0,0, "content", CellFormat); Sheet.addcell (label); Workbook.write (); Workbook.close ();
11. Handling line Breaks
New Writablecellformat (); Wcf.setwrap (true); Wcf.setverticalalignment (verticalalignment.centre ); Label labelNew label (0, 0,WCF);
Struts2 download Excel
PublicInputStream getInputStream () {Try{bytearrayoutputstream OS=NewBytearrayoutputstream (); Workbook Template= Workbook.getworkbook (NewFile ("C:\template.xls")); Writableworkbook Workbook=Workbook.createworkbook (os,template); Writablesheet sheet= Workbook.getsheet (0); CellFormat CellFormat= Sheet.getwritablecell (0, 0). Getcellformat (); Label Label=NewLabel (0,0, "content", CellFormat); Sheet.addcell (label); Workbook.write (); Workbook.close (); return NewBytearrayinputstream (Os.tobytearray ()); } Catch(Exception e) {logger.error (E.getmessage (), E); return NULL; } }
JXL API Summary