欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java读取Excle表格

程序员文章站 2022-03-07 22:29:25
...

package im.api.demo;

import java.io.File;
import java.io.IOException;

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

public class demo {
private static void readExcel() throws BiffException, IOException {
File xlsFile = new File(“E://temp/as1.xls”);
// 获得工作簿对象
Workbook workbook = Workbook.getWorkbook(xlsFile);
// 获得所有工作表
Sheet[] sheets = workbook.getSheets();
// 遍历工作表
if (sheets != null) {
for (Sheet sheet : sheets) {
// 获得行数
int rows = sheet.getRows();
// 获得列数
int cols = sheet.getColumns();
// 读取数据
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
Cell cell = sheet.getCell(col, row);
System.out.print(cell.getContents() + " ");
}
System.out.println();
}
}
}
workbook.close();
}

public static void main(String[] args) throws BiffException, IOException {
	demo.readExcel();
}

}

相关标签: java 读取Excle