您好,欢迎访问一九零五行业门户网

介绍java读取excel文件的方法

这篇文章主要为大家详细介绍了java读取excel文件的两种方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下
方式一:
借用
package com.ij34.util; /** * @author admin * @date 创建时间:2017年8月29日 下午2:07:59 * @version 1.0 *@type_name myclass */ import java.io.file; import java.io.ioexception; import jxl.cell; import jxl.sheet; import jxl.workbook; import jxl.read.biff.biffexception; public class test05 { public static void main(string args[]){ file f=new file("table01.xls"); try { workbook book=workbook.getworkbook(f);// sheet sheet=book.getsheet(0); //获得第一个工作表对象 for(int i=0;i<sheet.getrows();i++){ for(int j=0;j<sheet.getcolumns();j++){ cell cell=sheet.getcell(j, i); //获得单元格 system.out.print(cell.getcontents()+" "); } system.out.print("\n"); } } catch (biffexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
方式二:
package com.ij34.util; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import org.apache.poi.hssf.usermodel.hssfsheet; import org.apache.poi.hssf.usermodel.hssfworkbook; import org.apache.poi.ss.usermodel.cell; import org.apache.poi.ss.usermodel.dateutil; import org.apache.poi.ss.usermodel.row; /** * @author admin * @date 创建时间:2017年8月29日 下午4:01:06 * @version 1.0 *@type_name test02 *读取xls */ public class test02 { public static void main(string[] args) throws filenotfoundexception, ioexception { file excelfile = new file("table01.xls"); hssfworkbook wb = new hssfworkbook(new fileinputstream(excelfile)); hssfsheet sheet = wb.getsheetat(0); for (row row : sheet) { for (cell cell : row) { switch (cell.getcelltype()) { case cell.cell_type_string://字符串 system.out.print(cell.getrichstringcellvalue().getstring()); system.out.print(" "); break; case cell.cell_type_numeric://数值与日期 if (dateutil.iscelldateformatted(cell)) { system.out.print(string.valueof(cell.getdatecellvalue())); } else { system.out.print(cell.getnumericcellvalue()); } system.out.print(" "); break; case cell.cell_type_boolean://boolean类型 system.out.print(cell.getbooleancellvalue()); system.out.print(" "); break; default: } } system.out.println(); } } }
附jar包
以上就是介绍java读取excel文件的方法的详细内容。
其它类似信息

推荐信息