輸出excel的某個單元格
對于Excel檔案的字尾名是xls的情況
需要下載下傳jar包poi,網址:
https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-4.1.1-20191023.zip
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class excelread {
public static void main(String[] args) throws FileNotFoundException, IOException {
//得到Excel工作簿對象
//POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream("D:/briup/hadoop-eclipse/test/litest.xlsx"));
//得到Excel工作表對象
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("D:/briup/hadoop-eclipse/test/litest.xlsx"));
//根據index取得sheet對象
XSSFSheet sheet = wb.getSheetAt(0);
//取得有效的行數
int rowcount = sheet.getLastRowNum();
for(int i=0;i<rowcount;i++){
//擷取第三列
Row row = sheet.getRow(i);
//轉換成string
if(row != null){
int columNos = row.getLastCellNum();
Cell cell = row.getCell(3);
String er = cell.toString();
System.out.println(er);
}
}
}
}