JXL导Excel文件

1、导入jxl.jar包

2、代码实现

/**

*读取Excel文件

*filePath:excel文件路径

*/

public String readExcel(String filePath) {

    Date dateTime = new Date();

    try{

        //创建输入流

        InputStream stream = new FileInputStream(filePath);

        //获取Excel文件对象

        Workbook rwb = Workbook.getWorkbook(stream);

        //获取文件的指定工作表 默认的第一个

        Sheet sheet = rwb.getSheet(0);

        //行数(表头的目录不需要,从1开始)

        Integer id=null;

        for(int i=0; i<sheet.getRows(); i++){

            //创建一个数组 用来存储每一列的值

            String[] str = new String[sheet.getColumns()];

            Cell cell = null;

            //列数

            for(int j=0; j<sheet.getColumns(); j++){

                //获取第i行,第j列的值

                cell = sheet.getCell(j,i);

                str[j] = cell.getContents();

            }

        }catch(Exception e){

            e.printStackTrace();

        }

    return null;

}

发布了45 篇原创文章 · 获赞 5 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/L15810356216/article/details/82116769
今日推荐