I'm trying to build code to import an Excel file, I've been following a video but in the end my code didn't work (I double-checked) I get this error
I believe, I have the right libraries and perhaps the video might be a little outdated and the code no longer functions.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel ImportDataFromExcelModel = (DefaultTableModel) jTable1.getModel();
FileInputStream excelFIS = null;
BufferedInputStream excelBIS = null;
XSSFWorkbook excelImportWorkBook = null;
String currentDirectoryPath = "";
JFileChooser excelFileChooserImport = new JFileChooser(currentDirectoryPath);
int excelChooser = excelFileChooserImport.showOpenDialog(null);
if (excelChooser == JFileChooser.APPROVE_OPTION) {
try {
File excelFile = excelFileChooserImport.getSelectedFile();
excelFIS = new FileInputStream(excelFile);
excelBIS = new BufferedInputStream(excelBIS);
excelImportWorkBook = new XSSFWorkbook(excelBIS);
XSSFSheet excelSheet = excelImportWorkBook.getSheetAt(0);
for(int num = 0 ; num < excelSheet.getLastRowNum() ; num++){
XSSFRow excelRow = excelSheet.getRow(num);
XSSFCell cell = excelRow.getCell(1);
System.out.println(cell);
ImportDataFromExcelModel.addRow(new Object [] {cell});
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}