日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基于Apache POI 从xlsx读出数据

發布時間:2023/12/3 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于Apache POI 从xlsx读出数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【0】寫在前面

  • 0.1) these codes are from 基于Apache POI 的從xlsx讀出數據
  • 0.2) this idea is from http://cwind.iteye.com/blog/2187670 , adding some comments for easy understanding proves to be my work.

package com.cwind.poi; import java.io.File; import java.io.FileInputStream; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class SimpleDatasheetReader {public static void main(String[] args){try {File excel = new File("E:/bench-cluster/temp-resource/RunningMan.xlsx");FileInputStream fis = new FileInputStream(excel);

//創建工作簿

XSSFWorkbook book = new XSSFWorkbook(fis);

//創建工作簿下的第一頁紙張

XSSFSheet sheet = book.getSheetAt(0);

// 基于行的迭代器

Iterator<Row> itr = sheet.iterator(); System.out.println(itr.hasNext());

// Iterating over Excel file in Java

while (itr.hasNext()) {

//得到行

Row row = itr.next(); System.out.println(row.getLastCellNum());

// Iterating over each column of Excel file
// 基于行創建單元格 迭代器

Iterator<Cell> cellIterator = row.cellIterator();while (cellIterator.hasNext()) {

//依次 獲取某行的單元格

Cell cell = cellIterator.next();switch (cell.getCellType()) {

//下面是依據不同數據類型 打印出單元格的 數據

case Cell.CELL_TYPE_STRING:System.out.print(cell.getStringCellValue() + "\t");break;case Cell.CELL_TYPE_NUMERIC:if(DateUtil.isCellDateFormatted(cell)){System.out.print(cell.getDateCellValue() + "\t");}else{System.out.print(cell.getNumericCellValue() + "\t");}break;case Cell.CELL_TYPE_BOOLEAN:System.out.print(cell.getBooleanCellValue() + "\t");break;default:}}System.out.println("");}}catch(Exception ex){ex.printStackTrace();}} }

總結

以上是生活随笔為你收集整理的基于Apache POI 从xlsx读出数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。