JXL API Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.