`
piperzero
  • 浏览: 3475020 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

excel文件读取例子-jxl

 
阅读更多

注意版本是: 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;
}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics