TA的每日心情 | 无聊 2020-12-8 11:20 |
---|
签到天数: 605 天 连续签到: 1 天 [LV.9]测试副司令
|
读取excel的数据可以用jxl。。。比如举个例子:
public static String[][] getDataByTableName(String xlFilePath, String sheetName, String tableName) {
String[][] tabArray = null;
try {
InputStream stream = Tools.class.getClassLoader().getResourceAsStream(xlFilePath);
Workbook workbook = Workbook.getWorkbook(stream);
Sheet sheet = workbook.getSheet(sheetName);
int startRow, startCol, endDashRow, endCol, ci, cj;
Cell tableStart = sheet.findCell(tableName);
startRow = tableStart.getRow();
startCol = tableStart.getColumn();
Cell endDashCell = sheet.findCell(tableName, startCol + 1, startRow + 1, 100, 64000, false);
endDashRow = endDashCell.getRow();
endCol = endDashCell.getColumn();
tabArray = new String[endDashRow - startRow - 1][endCol - startCol - 1];
ci = 0;
for (int i = startRow + 1; i < endDashRow; i++, ci++) {
cj = 0;
for (int j = startCol + 1; j < endCol; j++, cj++) {
tabArray[ci][cj] = sheet.getCell(j, i).getContents();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return (tabArray);
} |
评分
-
查看全部评分
|