ciao a tutti,
ho iniziato ad usare Java dopo l'esperienza vb.net per manipolare files excel.
Ho un problema: da un file excel devo prendere il valore di una cella.
L'ambiente di sviluppo che utilizzo è netbeans.
Allora.....
il codice che ho scritto è:
l'errore generato è:codice:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: String file = jTextField1.getText(); File in = new File(file); Workbook w = null; int i=15; int j=2; try { try { w = Workbook.getWorkbook(in); } catch (BiffException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex); } Sheet sheet = w.getSheet(0); int lastrow=sheet.getRows(); Cell a1 = sheet.getCell(i,j); // riga che mi genera l'errore System.out.println(a1.getContents()); }
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 15
Se invece sostituisco le riga Cell a1 = sheet.getCell(i,j); con Cell a1 = sheet.getCell("A15"); l'output è quello desiderato. Oppure se il valore di i è 1 funziona.
Perchè?![]()
ciao
dottbin

Rispondi quotando