Wie das Lesen von Werten aus excel-Datei und speichern in Array?

Ich Lesen möchte excel-Arbeitsblatt-Werte und speichern diese Werte in einem array in Java.

Habe ich code bereit zum Lesen von excel-Blatt, aber ich bin nicht in der Lage, um es anzupassen, speichern Sie die Werte in Array.

Hier ist mein code zum Lesen einer excel-Tabelle :

package com.core.testscripts;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class NewExcel 
{

    private String inputFile;

    public void setInputFile(String inputFile) 
    {
        this.inputFile = inputFile;
    }

    public void read() throws IOException  
    {
        File inputWorkbook = new File(inputFile);
        Workbook w;
        try 
        {
            w = Workbook.getWorkbook(inputWorkbook);
            //Get the first sheet
            Sheet sheet = w.getSheet(0);
            //Loop over first 10 column and lines

            for (int j = 0; j < sheet.getColumns(); j++) 
            {
                for (int i = 0; i < sheet.getRows(); i++) 
                {
                    Cell cell = sheet.getCell(j, i);
                    System.out.println(cell.getContents());
                }
            }
        } 
        catch (BiffException e) 
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException 
    {
        NewExcel test = new NewExcel();
        test.setInputFile("D:/hellohowareyou.xls");
        test.read();
    }

}
Wie wollen Sie Lesen ? Alle Zellen aller Zeilen in einem array ? Oder alle Zellen pro Zeile in ein zwei-dimensionales array ??

InformationsquelleAutor Rishil Bhatt | 2012-03-26

Schreibe einen Kommentar