package com.rshz.excel.derive;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class Excels {
public static void main(String arg[]){
mx();
}
public static void mx(){
HSSFWorkbook workbook=null;
HSSFSheet sheet=null;
FileInputStream in=null;
try {
in=new FileInputStream("E:"+File.separator+"你好.xlsx");
workbook=new HSSFWorkbook(in);
sheet=workbook.getSheetAt(0);
Iterator<Row> it=sheet.rowIterator();
while(it.hasNext()){
HSSFRow row=(HSSFRow) it.next();
Iterator<Cell> tor=row.cellIterator();
while(tor.hasNext()){
HSSFCell cl=(HSSFCell)tor.next();
if(cl.getCellType()==Cell.CELL_TYPE_STRING){
System.out.print(cl.getStringCellValue()+"\t");
}else if(cl.getCellType()==Cell.CELL_TYPE_NUMERIC){
System.out.print(cl.getNumericCellValue()+"\t");
}else if(cl.getCellType()==Cell.CELL_TYPE_FORMULA){
}else if(cl.getCellType()==Cell.CELL_TYPE_BLANK){
}
}
System.out.println();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
输出结果:
性别 年龄 生日
李四 25.78 八月二十号
张三 26.3 四月三号