您可以在項目中添加Apache POI jar文件以使用Excel(XLSX)文件。 此外,附上示例代碼供您參考
void readXLSXFile(String fileName) throws IOException
{
FileInputStream fs= new FileInputStream(fileName);
XSSFWorkbook wb = new XSSFWorkbook(fs);
XSSFSheet ws = wb.getSheetAt(0);//you can change the value to index value of your required sheet
Iterator<Row> rows = ws.rowIterator();
XSSFRow row;
while(rows.hasNext())
{
row=(XSSFRow) rows.next();
XSSFCell cell=row.getCell(7);//8th cell of the row
String CName= cell.getStringCellValue(); //getting the cell value as string
countryNames(CName);// Your method for passing the country name to the method for your requirement
}
wb.close();
}
使用Apache POI或JExcel讀取excel文件 –