美文网首页
jxl读取多sheet的xls

jxl读取多sheet的xls

作者: 中v中 | 来源:发表于2021-05-27 07:44 被阅读0次

注意: 不支持 xlsx
添加依赖

<dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6.12</version>
        </dependency>

源码:

package test;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

import java.io.File;

public class Excel {
    public static void main(String[] args) throws Exception {
        File f = new File("d://test.xls");

        try {
            Workbook wb=Workbook.getWorkbook(f);
            int Num = wb.getNumberOfSheets();

            for (int i = 0; i < Num; i++) {
                Sheet sheet = wb.getSheet(i);
                Sheet s = wb.getSheet(i);

                int row = s.getRows();
                int col = s.getColumns();

                for(int i1=0; i1<row;i1++) {
                    for(int j=0;j<col;j++) {
                        Cell c =s.getCell(j, i1);
                        System.out.println(c.getContents());
                        //String text = c.getContents();
                    }
                }
            }
        } catch (Exception e) {
            e.getMessage();
        }

        System.out.println("completed");
    }
}

相关文章

网友评论

      本文标题:jxl读取多sheet的xls

      本文链接:https://www.haomeiwen.com/subject/kmkrsltx.html