4
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
  • 495
  • 4
  • 10
  • 21

1 Answers1

2

Chang your code from

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

to

Workbook workbook = Workbook.getWorkbook(new java.io.File(path));
Sabbath
  • 91
  • 3
  • 26
  • 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[] – Nimit_ZZ Jul 04 '12 at 09:22
  • 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 – Sabbath Jul 04 '12 at 09:54
  • 1
    Got it. I really appreciate the help. – Nimit_ZZ Jul 04 '12 at 10:00
  • 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 . – Sabbath Jul 04 '12 at 10:02