Reputation: 19
I am getting following error when I try to read an excel file in java although the file is present. I am in Windows environment. I have confirmed that that the file is present at that location.
java.io.FileNotFoundException: D:\myfile.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at jxl.Workbook.getWorkbook(Workbook.java:213)
My code is as follows:
wb = Workbook.getWorkbook(new File("D:/myfile.xls"));
Upvotes: 0
Views: 5847
Reputation: 153
In case you created the excel file beforehand, try to save it as a 97-2000 worksheet (So the old Excel format).
Upvotes: 0
Reputation:
Let me give you my example, code has been tested and let me know if this works.
File fileExcel = new File("D:/DATAVALUE.xls");
Workbook w;
w = Workbook.getWorkbook(fileExcel); Sheet sheet = w.getSheet(0);
I tested this code and let me captured this one for you.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package stackoverflow;
import java.io.File; import jxl.Cell; import jxl.Sheet; import jxl.Workbook;
/** * * @author jwijaya */ public class Stackoverflow {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try { File fileExcel = new File("D:/tes.xls"); Workbook w; w = Workbook.getWorkbook(fileExcel); Sheet sheet = w.getSheet(0); for (int j = 0; j < sheet.getRows(); j++) { for (int i = 0; i < sheet.getColumns(); i++) { Cell cell = sheet.getCell(i, j); if((j==0 && i==0 ) || (j==0 && i==1) || (j==0 && i==2) || (j==0 && i==3)) { System.out.println("Isi tabel " + cell.getContents()); } } Cell tanggal = sheet.getCell(0,j); String tanggalfinal = tanggal.getContents(); System.out.println(tanggalfinal); Cell datausd = sheet.getCell(1,j); String datausdfinal = datausd.getContents(); System.out.println(datausdfinal); Cell datajapan = sheet.getCell(2,j); String datajapanfinal = datajapan.getContents(); System.out.println(datajapanfinal); Cell dataaus = sheet.getCell(3,j); String dataausfinal = dataaus.getContents(); System.out.println(dataausfinal); } } catch (Exception e) { System.err.println("Got an exception!"); System.err.println(e.getMessage()); } } }
Download this file
https://hotfile.com/dl/204326337/3f04919/tes.xls.html
Upvotes: 0
Reputation: 121998
have tried with
wb = Workbook.getWorkbook(new File("D:\\myfile.xls"));
Al so see :File.separator or File.pathSeparator
Make sure that your file is in D drive.
Upvotes: 2