JAVA export EXCEL DEMO

Source: Internet
Author: User

[Java]
Package qs.com;
 
Import java. io. File;
 
Import jxl. Workbook;
Import jxl. write. Label;
Import jxl. write. WritableCellFormat;
Import jxl. write. WritableFont;
Import jxl. write. WritableSheet;
Import jxl. write. WritableWorkbook;
 
Public class Java2ExcelAction2 {
 
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
 
String path = "c :\\ JAVA2EXCELDEMO.xls ";
Try {
 
WritableWorkbook wbook = Workbook. createWorkbook (new File (path); // create an EXCEl File named java2exceldemo.xls and modify it all
 
WritableSheet wSheet = wbook. createSheet ("first page", 0); // name of a single page
WritableSheet wSheet2 = wbook. createSheet ("second page", 1 );
 

//
WSheet. mergeCells (0, 0, 8, 0); // merge cells (0, 0) (8, 0)
 

//
WritableFont wFont = new WritableFont (WritableFont. ARIAL, 10); // table Style

WritableCellFormat wCellFormat = new WritableCellFormat (wFont); // tableCell Style

WCellFormat. setAlignment (jxl. format. Alignment. CENTRE); // center horizontally
WCellFormat. setVerticalAlignment (jxl. format. VerticalAlignment. CENTRE); // center vertically
WCellFormat. setBorder (jxl. format. Border. ALL, jxl. format. BorderLineStyle. THIN); // set the Border
WCellFormat. setWrap (true); // wrap automatically
 


//

WSheet. addCell (new Label (1, 1, "B2", wCellFormat); // Add a string to a cell

WSheet. addCell (new Label (9, 2, "j3", wCellFormat ));
 


Wbook. write (); // write to www.2cto.com
Wbook. close (); // close, required

 
} Catch (Exception e) {// when createWorkbook is created, an Exception is thrown.
// TODO: handle exception
System. out. println (e. getMessage ());
E. printStackTrace ();
}
 
}
 
}

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.