控制台导入 execl
时间:2021-11-10 作者:匿名
package util; import 域名; import 域名InputStream; import 域名ception; import 域名tStream; import 域名yList; import 域名; import 域名; import 域名t; import 域名book; import 域名.BiffException; public class ExcelReader { /** * * @param excelFile 读取文件对象 * @param rowNum 从第几行开始读,如果有一行表头则从第二行开始读 * @return * @throws BiffException * @throws IOException */ public static List<String[]> readExcel(File excelFile,int rowNum) throws BiffException, IOException { // 创建一个list 用来存储读取的内容 List<String[]> list = new ArrayList<String[]>(); Workbook rwb = null; Cell cell = null; // 创建输入流 InputStream stream = new FileInputStream(excelFile); // 获取Excel文件对象 rwb = 域名orkbook(stream); // 获取文件的指定工作表 默认的第一个 Sheet sheet = 域名heet(0); // 行数(表头的目录不需要,从1开始) for (int i = rowNum-1; i < 域名ows(); i++) { // 创建一个数组 用来存储每一列的值 String[] str = new String[域名olumns()]; // 列数 for (int j = 0; j < 域名olumns(); j++) { // 获取第i行,第j列的值 cell = 域名ell(j, i); str[j] = 域名ontents(); } // 把刚获取的列存入list 域名(str); } // 返回值集合 return list; } public static void main(String[] args) { String excelFileName = "D:\\\\域名"; try { List<String[]> list = 域名Excel(new File(excelFileName),1); for (int i = 0; i < 域名(); i++) { String[] str = (String[])域名(i); for (int j = 0; j < 域名th; j++) { 域名tln(str[j]); } } } catch (BiffException e) { 域名tStackTrace(); } catch (IOException e) { 域名tStackTrace(); } } }