java读取Excle表格
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();
}
}
上一篇: 如何使用php设置文件上传的大小限制
下一篇: TP5实现支付宝电脑网站支付的示例介绍