博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用jxl对excel写文件简单例子
阅读量:3021 次
发布时间:2019-05-15

本文共 1239 字,大约阅读时间需要 4 分钟。

package com.yanek.test;

import java.io.File;

import java.io.IOException;

import jxl.Workbook;

import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class ExcelWrite {

/**

* @param args
*/
public static void main(String[] args) {

WritableWorkbook workbook = null;

try {

workbook = Workbook.createWorkbook(new File("c://test123.xls"));
WritableSheet ws=workbook.createSheet("test123",1);
Label label1=new Label(0,0,"aaa");
Label label2=new Label(1,0,"bbb");
Label label3=new Label(2,0,"ccc");
Label label4=new Label(0,1,"ddd");
Label label5=new Label(1,1,"eee");
Label label6=new Label(2,1,"fff");
try {
ws.addCell(label1);
ws.addCell(label2);
ws.addCell(label3);
ws.addCell(label4);
ws.addCell(label5);
ws.addCell(label6);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

workbook.write();

try {
workbook.close();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

转载地址:http://wfdic.baihongyu.com/

你可能感兴趣的文章