public class ExcelUtil {
public static void main(String[] args) {
ExcelUtil eu = new ExcelUtil();
eu.run("1.xls");
}
private void run(String filename) {
try {
InputStream is = new FileInputStream(filename);// 得到文件流
jxl.Workbook rwb = Workbook.getWorkbook(is);// 工作表
jxl.Sheet rs = rwb.getSheet(1); // 读取第一个工作表的数据 sheet
int num = rs.getRows();// 得到此excel有多少行..
for (int i = 0; i < num; i++) {
Cell[] cell = rs.getRow(i);// 得到第i行的数据..返回cell数组
for (int j = 0; j < cell.length; j++) {
System.out.print(cell[j].getContents() + " ");
}
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
}
}
}
读取excel
最新推荐文章于 2024-09-16 09:47:29 发布