您的位置:首页 > 其它

今天遇到一个poi导入的问题 参考别人的写了一个

2016-04-01 22:17 603 查看
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
四月三号
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: