user2927486:
私は、動的データはExcelから来る要求を有し、そしてIは、配列リストにヘッダ(カラム)名(1行目)を抽出する必要があります。
ファイル=新しいFileInputStreamを(新しいファイル( "Excelファイル")); HSSFWorkbookワークブック=新しいXSSFWorkbook(ファイル);
任意の入力が大幅に私は、Javaプログラミングに非常に新しいです、感謝します。
感謝
アービンド・クマールのAvinash:
次のように実行します。
// Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
// Get the first sheet from the workbook
XSSFSheet firstSheet = workbook.getSheetAt(0);
// Get the first row from the sheet
Row row = firstSheet.getRow(0);
// Create a List to store the header data
ArrayList<String> headerData = new ArrayList<>();
// Iterate cells of the row and add data to the List
for (Cell cell : row) {
switch (cell.getCellType()) {
case NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
DataFormatter dataFormatter = new DataFormatter();
headerData.add(dataFormatter.formatCellValue(cell));
} else {
headerData.add(String.valueOf(cell.getNumericCellValue()));
}
break;
case STRING:
headerData.add(cell.getStringCellValue());
break;
case BOOLEAN:
headerData.add(String.valueOf(cell.getBooleanCellValue()));
break;
default:
headerData.add("");
break;
}
}
// Print the List
System.out.println(headerData);
何の疑いも/問題の場合にはコメントをお気軽に。