英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论