package bt_lose;
import java.io.*;
import jxl.*;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;
/**
* 创建xls文件
*
* @author botao
*
*/
public class JxlTest {
public static void main(String[] args) {
WritableWorkbook book = null;
try {
int i = 0;
// Workbook.createWorkbook(File file);
// Workbook.createWorkbook(OutputStream out);
// Workbook.createWorkbook(File file, Workbook book);
// Workbook.createWorkbook(OutputStream out,Workbook book);
WorkbookSettings sett = new WorkbookSettings();
Workbook.createWorkbook(new File(""), sett);
book = Workbook.createWorkbook(new File("d:/test.xls"));// 创建文件
WritableSheet sheet = book.createSheet("first", i++);// 创建工作表
WritableSheet sheet2 = book.createSheet("second", i++);// 创建工作表
sheet.setRowView(0, 3000);
sheet.setColumnView(0, 1000);
Label label = new Label(0, 0, "测试00");// 创建单元格Label(int col, int
// row, String
// str);col列索引,row行索引,从0开始,str数据
Label label1 = new Label(0, 1, "测试01");// 创建单元格
Label label2 = new Label(1, 0, "测试10");// 创建单元格
Label label3 = new Label(1, 1, "测试11");// 创建单元格
jxl.write.Number number = new jxl.write.Number(1, 0, 789.123);// 存放数字的单元格,构造方法和上面类似。
sheet.addCell(label);// 添加单元格到工作表中
sheet.addCell(label1);// 添加单元格到工作表中
sheet.addCell(label2);// 添加单元格到工作表中
sheet.addCell(label3);// 添加单元格到工作表中
sheet2.addCell(number);// 添加单元格到工作表中
book.write();// 写数据
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (book == null) {
try {
book.close();// 关闭流
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}