import java.io.*;
import jxl.*;
import jxl.write.*;
import jxl.format.*;
import java.util.*;
import java.awt.Color;
public class TestExcel {
public static void writeExcel(File f) throws Exception {
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(f);
jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);
jxl.write.Label labelC = new jxl.write.Label(0, 0, "我爱中国");
ws.addCell(labelC);
jxl.write.WritableFont wfc = new jxl.write.WritableFont(
WritableFont.ARIAL, 20, WritableFont.BOLD, false,
UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);
jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(
wfc);
wcfFC.setBackground(jxl.format.Colour.RED);
labelC = new jxl.write.Label(6, 0, "中国爱我a", wcfFC);
ws.addCell(labelC);
// 写入Exel工作表
wwb.write();
// 关闭Excel工作薄对象
wwb.close();
}
public static void readExcel(File os) throws Exception {
Workbook wb = Workbook.getWorkbook(os);
Sheet s = wb.getSheet("Sheet1");
Cell c = s.getCell(0,0);
System.out.println(c.getContents());
}
// 最好写一个这样的main方法来测试一下你的这个class是否写好了。
public static void main(String[] args) throws Exception {
File f = new File("c:\\kk1.xls");
// f.createNewFile();
// writeExcel(f);
readExcel(f);
}
}
posted on 2007-10-26 09:23
lk 阅读(809)
评论(0) 编辑 收藏 所属分类:
j2se
超速成)"
trackback:ping="http://www.blogjava.net/lcs/services/trackbacks/156014.aspx" />
-->