1,导入的实例类
public String doImp(File file) throws IOException {
String msg = "";
InputStream io = new FileInputStream(file);
POIFSFileSystem fs = new POIFSFileSystem(io);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet1 = wb.getSheetAt(0);
int k = 0;
HSSFRow row =null;
while (true) {
row = sheet1.getRow(k);
if(row!=null){
HSSFCell cell = row.getCell((short) 0);
String value = ExcelUtil.cell2String(cell);
System.out.println(value);
k++;
}
}
}
2,cell2String方法:
public static String cell2String(HSSFCell cell) {
if(cell.getCellType() == HSSFCell.CELL_TYPE_STRING){
return cell.getStringCellValue();
}else if(cell.getCellType() ==HSSFCell.CELL_TYPE_NUMERIC){
double millimit_d = cell.getNumericCellValue();
String millimit = currencyFmt.format(millimit_d).toString();
return millimit;
}
else{
return "";
}
}
3,private final static DecimalFormat currencyFmt = new DecimalFormat("#####0.######");//用来格式化通过double类型取出来的数据