Excel檔案讀取
阿新 • • 發佈:2018-12-27
專案結構:
xml檔案內容:
讀取程式碼:
private void ReaderXml() { InputStream is = null; try { is = getAssets().open("aaa.xls"); Workbook book = Workbook.getWorkbook(is); book.getNumberOfSheets(); // 獲得第一個工作表物件 Sheet sheet = book.getSheet(0); int Rows = sheet.getRows(); int Columns = sheet.getColumns(); for (int i = 0; i < Rows; ++i) { //將每一列的資料讀取 String id = (sheet.getCell(0, i)).getContents(); String areaCode = (sheet.getCell(1, i)).getContents(); String subName = (sheet.getCell(2, i)).getContents(); String nameCn = (sheet.getCell(3, i)).getContents(); String nameEn = (sheet.getCell(4, i)).getContents(); String capitalCn = (sheet.getCell(5, i)).getContents(); Log.e(TAG, "ReaderXml:id " + id); Log.e(TAG, "ReaderXml:areaCode " + areaCode); Log.e(TAG, "ReaderXml:subName " + subName); Log.e(TAG, "ReaderXml:nameCn " + nameCn); Log.e(TAG, "ReaderXml:nameEn " + nameEn); Log.e(TAG, "ReaderXml:capitalCn " + capitalCn); Log.e(TAG, "ReaderXml:------------------------------ "); } book.close(); } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { e.printStackTrace(); } }
輸出結果: