public class TestUtil extends TestBase {
TestUtil testUtil;
static Workbook book;
static Sheet sheet;
public void switchToFrame() {
driver.switchTo().frame("mainpanel");
}
public static String TESTDATA_SHEET_PATH = ".\\src\\main\\java\\com\\testData\\FreeCRMTestData.xlsx";
public static Object[][] getTestData(String sheetName) {
FileInputStream file = null;
try {
file = new FileInputStream(TESTDATA_SHEET_PATH);
} catch (Exception e) {
e.printStackTrace();
}
try {
book = WorkbookFactory.create(file);
} catch (Exception e) {
e.printStackTrace();
}
// Get the Sheet.
sheet = book.getSheet(sheetName);
//getLastRowNum() Gets the number last row on the sheet.
//getLastCellNum() Gets the index of the last cell contained in this row PLUS ONE.
Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
for (int i = 0; i < sheet.getLastRowNum(); i++) {
for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) {
data[i][k] = sheet.getRow(i + 1).getCell(k).toString();
}
}
return data;
}
}
描述: - 我想从 Java 中读取一个 X 列 Y 行的 Excel 文件。语句 Object[][] data = new Object [][] 是什么意思?任何人都可以给我整个代码片段的简单评论吗?
斯蒂芬大帝
慕田峪7331174
叮当猫咪
相关分类