首页 > 编程 > Java > 正文

java 读取excel内容具体代码

2019-11-26 15:57:11
字体:
来源:转载
供稿:网友

1. 需要下载jxl.jar包,自己研究了一下,代码如下

复制代码 代码如下:

package file;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.*;
import jxl.Sheet;
import jxl.Cell;
import jxl.Workbook;

public class excel {

/**
* @param args
* @throws IOException
* @throws BiffException
*/
public static void main(String[] args) throws BiffException, IOException {
// TODO Auto-generated method stub
Workbook book = Workbook.getWorkbook(new File("F://Center20130902update.xls"));
Sheet sheet=book.getSheet(0);

ArrayList list = new ArrayList();

for(int k=2;k<96;k++){
Map rowData = new HashMap();
for(int j=2;j<5;j++){
Cell cell = sheet.getCell(j,k);//列,行
Cell keycell = sheet.getCell(j,1);
String key = keycell.getContents();
String Content = cell.getContents();
rowData.put(key, Content);
}
list.add(rowData);
}

System.out.println(list);

book.close();

}

}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表