【发布时间】:2017-08-16 07:58:12
【问题描述】:
请在下方找到代码 sn-p
public class DataDriven_GetDataExcel {
public static void main(String[] args) throws IOException, EncryptedDocumentException, InvalidFormatException {
//1 Getting Control over File
FileInputStream fis = new FileInputStream("C:\\Users\\bewosaurabh\\Documents\\GetDataFile.xlsx");
//2 Creating a Workbook
Workbook wb = WorkbookFactory.create(fis);
//3 Getting Control over Sheet
Sheet sh = wb.getSheet("Sheet1");
.
......
我不明白为什么我们需要在读取 Excel 文件之前创建一个工作簿? Excel 文件也称为工作簿(如下图所示)。
当我们创建一个 excel 文件时,这意味着我们正在创建一个工作簿。从那里,我们访问表格,然后是行和列。
当我们已经有一个“工作簿”时,我不明白为什么要写WorkbookFactory.create(fis);
我们应该有一些方法来获取我们创建的工作簿,就像我们为 Rows(getRow)、Sheets (getSheet)、Cells (getCell) 所做的那样。
你能帮我理解 POI 吗?
【问题讨论】:
-
WorkbookFactory.create不会创建工作簿(Excel 文件)。它实例化一个代表工作簿的类。 -
哦..好的,非常感谢@GSerg
标签: excel selenium-webdriver apache-poi