Reading content from an Excel file

一世执手 提交于 2019-12-09 13:42:21

问题


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.


回答1:


Chang your code from

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

to

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


来源:https://stackoverflow.com/questions/11326031/reading-content-from-an-excel-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!