package com;
import java.io.File;
import java.io.IOException;
import org.omg.CORBA.WStringSeqHelper;
import jxl.Workbook;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Exceldown {
public static void main(String args[]) throws RowsExceededException, WriteException {
WritableWorkbook bookWorkbook=null;
try {
bookWorkbook = Workbook.createWorkbook(new File("d:Test.xls"));
}
catch (IOException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
WritableSheet sheet=bookWorkbook.createSheet("sheet1", 0);
WritableFont bwf=new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false);
jxl.write.WritableCellFormat cb=new jxl.write.WritableCellFormat(bwf);
cb.setBorder(jxl.format.Border.ALL, BorderLineStyle.MEDIUM);
cb.setAlignment(jxl.write.Alignment.CENTRE);
cb.setVerticalAlignment(VerticalAlignment.CENTRE);
//jxl.write.Label label2=new jxl.write.Label(1,0,"年龄");
for(int i=2;i<9;i++){ sheet.setColumnView(i, 15);
}
//需要合并的单元格
sheet.mergeCells(1, 1, 1, 2);
sheet.mergeCells(1, 3, 1, 8);
sheet.mergeCells(2, 1, 2, 2);
sheet.mergeCells(3, 1, 4, 1);
sheet.mergeCells(5, 1, 8, 1);
//单元格赋值
Label label=new Label(1, 1, "**", cb);
Label label1=new Label(1, 3, "**", cb);
Label label2=new Label(2, 1, "**", cb);
Label label3=new Label(3, 1, "**", cb);
Label label4=new Label(3, 2, "**", cb);
Label label5=new Label(4, 2, "**", cb);
Label label6=new Label(5, 1, "**", cb);
Label label7=new Label(5, 2, "**", cb);
Label label8=new Label(6, 2, "**", cb);
Label label9=new Label(7, 2, "**", cb);
Label label10=new Label(8, 2, "**", cb);
Label label11=new Label(9, 1, "**", cb);
Label label12=new Label(9, 2, "**", cb);
Label label13=new Label(2, 3, "**", cb);
Label label14=new Label(2, 4, "**", cb);
Label label15=new Label(2, 5, "**", cb);
Label label16=new Label(2, 6, "**", cb);
Label label17=new Label(2, 7, "**", cb);
Label label18=new Label(2, 8, "**", cb);
try {
//将赋予的值放到sheet对应单元格
sheet.addCell(label);
sheet.addCell(label1);
sheet.addCell(label2);
sheet.addCell(label3);
sheet.addCell(label4);
sheet.addCell(label5);
sheet.addCell(label6);
sheet.addCell(label7);
sheet.addCell(label8);
sheet.addCell(label9);
sheet.addCell(label10);
sheet.addCell(label11);
sheet.addCell(label12);
sheet.addCell(label13);
sheet.addCell(label14);
sheet.addCell(label15);
sheet.addCell(label16);
sheet.addCell(label17);
sheet.addCell(label18);
bookWorkbook.write();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
bookWorkbook.close();
}
catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}