Lesen Sie mehrere excel-sheets in java

Ich versuche, fügen Sie Werte aus mehreren sheets einer Excel-Dokument zu einer ArrayList. ohne Verwendung HSSFSheet. dies scheint einfacher, zu denken.Seien Sie vorsichtig und vergessen Sie nicht, ändern Sie Typ Zeichenfolge numerisch.

public void setinputfile(String inputfile) {
    this.inputfile = inputfile;}

public void read() throws IOException {
    File inputWorkbook = new File(inputfile);

    try {
        Workbook w = Workbook.getWorkbook(inputWorkbook);
        int Num = w.getNumberOfSheets();
        for (int i = 0; i < Num; i++) {
            Sheet sheet = w.getSheet(i);
            Sheet s = w.getSheet(i);
            int row = s.getRows();
            int col = s.getColumns();
            for (int i1 = 0; i1 < row; i1++) {
                inner = new ArrayList<Double>();
                for (int j = 0; j < col; j++) {
                    Cell c = s.getCell(j, i1);
                    CellType type = c.getType();
                    System.out.println(c.getContents());
                    String text = c.getContents(); //example String
                    double value = Double.parseDouble(text);
                    inner.add(value);
                }
                Kargo_Amount.add(inner);
            }

        }
    } catch (BiffException e) {
        e.printStackTrace();
    }
}
public static void main(String[] args) throws Exception {
    Facility_Location test = new Facility_Location();
    test.setinputfile("C:\\Users\\soheyl\\Desktop\\Kargo miktarii.xls");
    test.read();
}
Schreibe einen Kommentar