Reading content from an Excel file

14,404

Chang your code from

Workbook workbook = Workbook.getWorkbook(File(path));

to

Workbook workbook = Workbook.getWorkbook(new java.io.File(path));
Share:
14,404
Nimit_ZZ
Author by

Nimit_ZZ

Updated on June 09, 2022

Comments

  • Nimit_ZZ
    Nimit_ZZ about 2 years
    package jexcel.jxl.nimit;
    
    import java.io.*;  
    
    import jxl.Cell;  
    import jxl.Sheet;  
    import jxl.Workbook;  
    import jxl.read.biff.BiffException;  
    import jxl.read.biff.File;  
    
    public class ExampleJxl {  
    
        /**
         * @param args
         */
        public static void main(String[] args)throws IOException, BiffException {
            ExampleJxl.ExcelFile("D:/nimit.xls");
        }
    
    public static String ExcelFile(String path){    
    
        Workbook workbook = Workbook.getWorkbook(File(path));
        Sheet sheet = workbook.getSheet(0); 
        Cell a1 = sheet.getCell(0,0);
        Cell a2 = sheet.getCell(0,1);
        String s1=a1.getContents();
        String s2=a2.getContents();
        System.out.println("My name is"+a1+"\t"+a2);
         }  
    }
    

    I don't understand why the File(path) show a error The method File(String) is undefined for the type ExampleJxl I'm trying to print my name entered in the excel file.

  • Nimit_ZZ
    Nimit_ZZ almost 12 years
    If I do that I get the following message The constructor File(String) is undefined and it asks me to change the type of path to byte[]
  • Sabbath
    Sabbath almost 12 years
    You imported 'jxl.read.biff.File' after 'java.io.*' . So the compiler recognized the File as jxl.read.biff.File but not java.io.File . Workbook.getWorkbook(File) needs java.io.File . I edited the answer , try it . @USER_ZZ
  • Nimit_ZZ
    Nimit_ZZ almost 12 years
    Got it. I really appreciate the help.
  • Sabbath
    Sabbath almost 12 years
    No , if both jxl.read.biff.File and java.io.File are used in your source , whether you move which one before the other , you have to use full class name of the former class to new it .