注意版本是: 2003 excel格式
package com.yanek.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String path="C://001.xls";
InputStream in = null;
Workbook workbook = null;
try {
in = read(path);
try {
workbook = Workbook.getWorkbook(in);
Sheet[] sheets = workbook.getSheets();
for (int i = 0; i < sheets.length; i++)
{
int row_count = sheets[i].getRows();
// String auctionCode[] = new String[row_count];
for (int j = 1; j < row_count; j++)
{
// 解析一行数据
Cell[] row = sheets[i].getRow(j);
String auction_code = row[0].getContents().trim();
String name = row[1].getContents().trim();
//codes.add(auction_code);
//System.out.println("auction_code=="+auction_code);
// System.out.println("name=="+name);
// System.out.println("row.length=="+row.length);
int len =row.length;
for (int k=0;k<len;k++)
{
String temp = row[k].getContents().trim();
System.out.println("xxx====:"+temp);
}
}
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static InputStream read(String localPath)throws Exception
{
InputStream in = null;
try {
in = new FileInputStream(localPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return in;
}
}