import jxl.Cell;
import jxl.Workbook;
import java.io.FileInputStream;
import java.io.InputStream;
public class Main {
public static void main(String[] args) {
try {
InputStream is = new FileInputStream("d:/t1.xls"); // savePath是文件的绝对路径如c:/aa.xls
jxl.Workbook wb = Workbook.getWorkbook(is); // 得到工作薄
jxl.Sheet[] sts = wb.getSheets(); // 获得所有的工作表
for (jxl.Sheet st : sts) { // 得到工作薄中的第一个工作表 (有多个表的时候遍历sts)
int rsRows = st.getRows(); // 得到excel的总行数
int columncount = st.getColumns();// 获得excel的总列数
System.out.println("共" + rsRows + "行 " + columncount + "列");
for (int i = 0; i < rsRows; i++) {
Cell cell0 = st.getCell(0, i);// 得到工作表的第一个单元格,即A1
Cell cell1 = st.getCell(1, i);// 得到工作表的第二个单元格,即B1
String str1 = cell0.getContents(); // 获得单元格内的内容
String str2 = cell1.getContents(); // 获得单元格内的内容
System.out.print(str1 + ",");
System.out.println(str2);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
//共3行 2列
//名称1,12
//名称2,14
//名称3,13
用到jxl-2.6.12.jar
转自:http://blog.youkuaiyun.com/ye1992/article/details/9292705