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);
     }  
}

我不明白为什么 File(path) 显示错误The method File(String) is undefined for the type ExampleJxl 我试图打印我在 Excel 文件中输入的姓名。

4

1 回答 1

2

更改您的代码

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

Workbook workbook = Workbook.getWorkbook(new java.io.File(path));
于 2012-07-04T09:20:58.453 回答