Voglio leggere i valori del foglio excel e archiviare tali valori in un array in Java.Come leggere i valori dal file excel e memorizzarli nell'array?
Ho codice pronto per leggere il foglio excel ma non sono in grado di personalizzarlo per archiviare tali valori in Array.
Ecco il mio codice per leggere un foglio di Excel:
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();
}
}
Come vuoi leggere? Tutte le celle di tutte le righe in un singolo array? O tutte le celle per fila in un array bidimensionale ?? – Nik