`getWorkbook(FileInputStream)`方法在`Workbook`类型中未定义。

huangapple go评论82阅读模式
英文:

The method getWorkbook(FileInputStream) is undefined for the type Workbook

问题

我正在尝试使用Java编写Selenium代码,使用Apache POI从Excel中获取输入。以下是代码,我收到错误消息:“The method getWorkbook(FileInputStream) is undefined for the type Workbook” ,出现在语句Workbook wb = Workbook.getWorkbook(fs); 请帮助我解决这个问题。

public class Main {

    public static void main(String[] args) {

        File file = new File("C:/Users/425413/NewWorkspace/Telecom/datafile.properties");

        FileInputStream fileInput = null;
        try {
            fileInput = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Properties prop = new Properties();

        //load properties file
        try {
            prop.load(fileInput);
        } catch (IOException e) {
            e.printStackTrace();
        }


        System.setProperty("webdriver.chrome.driver","C:\\Users\5413\\Documents\\Raji\\chromedriver_win32-for79\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get(prop.getProperty("URL"));

        String FilePath = "d://filepath.xls";
        FileInputStream fs = new FileInputStream(FilePath);
        Workbook wb = Workbook.getWorkbook(fs);

    }

}

希望这能帮助您解决问题。

英文:

I'm trying to write a Selenium code with JAVA for fetching input from excel using Apache POI. Below is the code, I'm getting the error message 'The method getWorkbook(FileInputStream) is undefined for the type Workbook' for the statement Workbook wb = Workbook.getWorkbook(fs); Please help me to sort this out.

public class Main {

	public static void main(String[] args) {
		
		  File file = new File("C:/Users/425413/NewWorkspace/Telecom/datafile.properties");
		  
			FileInputStream fileInput = null;
			try {
				fileInput = new FileInputStream(file);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			Properties prop = new Properties();
			
			//load properties file
			try {
				prop.load(fileInput);
			} catch (IOException e) {
				e.printStackTrace();
			}
		
		
		System.setProperty("webdriver.chrome.driver","C:\\Users\5413\\Documents\\Raji\\chromedriver_win32-for79\\chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.get(prop.getProperty("URL"));
		
		String FilePath = "d://filepath.xls";
		FileInputStream fs = new FileInputStream(FilePath);
		Workbook wb = Workbook.getWorkbook(fs);

	}

}

答案1

得分: 1

尝试使用

WorkbookFactory.create
英文:

Try with

 WorkbookFactory.create

huangapple
  • 本文由 发表于 2020年10月20日 21:09:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64445878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定