主题 : Java读取数据Excel
级别: 白丁
UID: 35830
积分:72 加为好友
威望: 0 精华: 0
主题:2 回复:73
注册时间:2012-07-04
在线时长:0
1#   发表于:2013-09-12 15:00:25  IP:119.15.*.*

import java.io.File;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class ReadXLS {

public static void main(String args[]) {

try {
Workbook book = Workbook.getWorkbook(new File(
"e:\\档案2.xls"));
Sheet sheet = book.getSheet(0);
Cell cell1 = sheet.getCell(0, 0);
String result = cell1.getContents();
System.out.println("文件标题:" + result);
int rows = sheet.getRows();
int columns = sheet.getColumns();
System.out.print("文件结构:" + rows + "行,");
System.out.println(columns + "列");
for (int i = 0; i < rows; i++) {

for (int j = 0; j < columns; j++) {
System.out.print(sheet.getCell(j, i).getContents() + "\t");

}
System.out.println();
}
book.close();
} catch (Exception e) {
// System.out.println(e);
e.printStackTrace();
}
}
}
1 共1页