日期:2014-05-20 浏览次数:20940 次
import jxl.*;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import jxl.write.Number;
import jxl.write.Boolean;
import java.io.*;
public class ExcelHandle
{
publicExcelHandle()
{
}
publicstatic void readExcel(String filePath)
{
try
{
InputStream is = new FileInputStream(filePath);
Workbook rwb = Workbook.getWorkbook(is);
//Sheet st =rwb.getSheet(0);//这里有两种方法获取sheet表,一是表名,二是下标(从0开始)
Sheet st = rwb.getSheet("Sheet1");
Cell c00 = st.getCell(3,0);//第一个代表列,第二个代表行,下标从0开始
//通用的获取cell值的方式,返回字符串
String strc00 = c00.getContents();
//获得cell具体类型值的方式
if(c00.getType() == CellType.LABEL)
{
LabelCell labelc00 = (LabelCell)c00;
strc00 = labelc00.getString();
}
//输出
System.out.println(strc00);
//关闭
rwb.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
publicstatic void writeExcel(OutputStream os)
{
try
{
WritableWorkbook wwb = Workbook.createWorkbook(os);
//创建Excel工作表 指定名称和位置
WritableSheet ws = wwb.createSheet("Test Sheet 1",0);