[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 ();
}
}
}