JAVA实现页面表格数据导出到execl通用方法(POI)(三)

2014-11-24 02:03:57 · 作者: · 浏览: 1
if (textValue != null) {

Pattern p = Pattern.compile("^\\d+(\\.\\d+) $");

Matcher matcher = p.matcher(textValue);

if (matcher.matches()) {

// 是数字当作double处理

cell.setCellValue(Double.parseDouble(textValue));

} else {

HSSFRichTextString richString = new HSSFRichTextString(

textValue);

HSSFFont font3 = workbook.createFont();

font3.setColor(HSSFColor.BLUE.index);

richString.applyFont(font3);

cell.setCellValue(richString);

}

}

} catch (SecurityException e) {

e.printStackTrace();

e=null;

} catch (NoSuchMethodException e) {

e.printStackTrace();

e=null;

} catch (IllegalArgumentException e) {

e.printStackTrace();

e=null;

} catch (IllegalAccessException e) {

e.printStackTrace();

e=null;

} catch (InvocationTargetException e) {

e.printStackTrace();

e=null;

} finally {

// 清理资源

}

}

}

try {

workbook.write(out);

} catch (IOException e) {

e.printStackTrace();

e=null;

}

}