首页 > 解决方案 > 类型 Workbook 的方法 getWorkbook(FileInputStream) 未定义

问题描述

我正在尝试使用 JAVA 编写 Selenium 代码,以使用 Apache POI 从 excel 中获取输入。下面是代码,我收到错误消息'The method getWorkbook(FileInputStream) is undefined for the type Workbook' for the statement 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\\425413\\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);

    }

}

标签: javaexcelseleniumapache-poi

解决方案


尝试

 WorkbookFactory.create

推荐阅读