sto usando jxl per leggere una colonna di un foglio excel.
dovrei leggere tutte le righe di una colonna se queste non sono vuote.
le colonne hanno solo indirizzi email, quindi sono stringhe.
ho provato così:
codice:
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ExcelReader {
public static void readEmail() throws IOException, BiffException {
Workbook wb = Workbook.getWorkbook(new File("/home/matte/Desktop/email.xls"));
Sheet sh = wb.getSheet(0);
Cell cl = null;
for (int i = 0; i < 100; i++) {
if (!"".equals((sh.getCell(0, i)).getContents())) {
cl = sh.getCell(0, i);
}
}
String address = cl.getContents();
System.out.println(address);
wb.close();
}
public static void main(String[] args) throws IOException, BiffException {
readEmail();
}
}
dove per ora 100 l'ho messo a mano, ma vorrei che fosse automatico.
l'errore restituito è:
codice:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
at com.mattepuffo.mail.ExcelReader.readEmail(ExcelReader.java:17)
at com.mattepuffo.mail.ExcelReader.main(ExcelReader.java:27)
Java Result: 1
ma nn capisco il perchè.
secondo voi come posso fare?