欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java使用poi读取excel文件代码示例,poiexcel,ParseExcel.j

来源: javaer 分享于  点击 19749 次 点评:64

java使用poi读取excel文件代码示例,poiexcel,ParseExcel.j


ParseExcel.java

package cn.outofmemory.utilit;import java.io.FileInputStream;import java.io.IOException;import org.apache.poi.hssf.usermodel.*;import org.apache.poi.poifs.filesystem.POIFSFileSystem;/** * @author la *POI工具读取Excel文件 */public class ParseExcel {    private void parseExcel(String excelFile)throws IOException {        POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream(excelFile));//打开Excel文件        HSSFWorkbook wbHssfWorkbook=new HSSFWorkbook(fs);//打开工作薄        HSSFSheet sheet=wbHssfWorkbook.getSheetAt(0);//打开工作表        HSSFRow row=null;        String data=null;        for (int i = 0; i <=sheet.getLastRowNum(); i++) {//循环读取每一行            row =sheet.getRow(i);            for (int j = 0; j <= row.getLastCellNum(); j++) {//循环读取每一列                switch (row.getCell((short)j).getCellType()) {//判断单元格的数据类型                case HSSFCell.CELL_TYPE_BLANK:                    data="";                    break;                case HSSFCell.CELL_TYPE_NUMERIC:                    data=(long)row.getCell((short)j).getNumericCellValue()+"";                    break;                default:                    data=row.getCell((short)j).getStringCellValue();                    break;                }                System.out.print(data+"\t");            }            System.out.println();        }    }    /**     * @param args     *2012-10-23     *void     */    public static void main(String[] args)throws IOException {        new ParseExcel().parseExcel(args[0]);    }}
相关栏目:

用户点评