java 从 Excel 文件中读取内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11326031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:40:24  来源:igfitidea点击:

Reading content from an Excel file

javajxljxls

提问by Nimit_ZZ

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 ExampleJxlI'm trying to print my name entered in the excel file.

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

采纳答案by Sabbath

Chang your code from

更改您的代码

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

to

Workbook workbook = Workbook.getWorkbook(new java.io.File(path));