Quiero leer los valores de hoja de Excel y almacenar esos valores en una matriz en Java.¿Cómo se leen los valores del archivo excel y se almacenan en Array?
Tengo el código listo para leer la hoja de Excel, pero no puedo personalizarlo para almacenar esos valores en Array.
Aquí está mi código para leer una hoja de 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();
}
}
¿Cómo quiere leer? Todas las celdas de todas las filas en una sola matriz? ¿O todas las celdas por fila en una matriz bidimensional? – Nik