使用的是一个叫Java Excel API的东西,类似的还有jakarta的POI,不过感觉那个太复杂了点儿。而且jxl对中文的支持相当的好,至少我在用的过程中一点问题没出。
一、下载地址:http://www.andykhan.com/jexcelapi/
二、特性:可以读取Excel 95, 97, 2000文件,可以读或写Excel 97及其以后版本的的公式(不过我发现好像有bug),生成Excel 97格式的电子 表格,支持字体、数字和日期格式化,支持单元格的颜色和阴影,可以编辑现有的文件
三、读文件
//声明一下,记得后面要关闭。。
Workbook workbook
=
null
;
try ... {
workbook = Workbook.getWorkbook(new
File("d:/temp/TestRead.xls"));
} catch (Exception e) ... {
throw new Exception("file to import not found!");
}
Sheet sheet = workbook.getSheet( 0 );
Cell cell = null ;
int columnCount = 3 ;
int rowCount = sheet.getRows();
for ( int i = 0 ; i < rowCount; i ++ ) ... {
for (int j = 0; j <columnCount; j++) ...{
//注意,这里的两个参数,第一个是表示列的,第二才表示行
try ... {
workbook = Workbook.getWorkbook(new
File("d:/temp/TestRead.xls"));
} catch (Exception e) ... {
throw new Exception("file to import not found!");
}
Sheet sheet = workbook.getSheet( 0 );
Cell cell = null ;
int columnCount = 3 ;
int rowCount = sheet.getRows();
for ( int i = 0 ; i < rowCount; i ++ ) ... {
for (int j = 0; j <columnCount; j++) ...{
//注意,这里的两个参数,第一个是表示列的,第二才表示行