// 如果不是圖檔資料,就利用正規表達式判斷textValue是否全部由數字組成
if (textValue != null) {
Pattern p = Pattern.compile("^\\d+(\\.\\d+)?$");
Matcher matcher = p.matcher(textValue);
if (matcher.matches()) {
cell.setCellValue(Double.parseDouble(textValue));// 是數字當作double處理
style2.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//excel 自定義的格式
cell.setCellStyle(style2);
} else {
HSSFRichTextString richString = new HSSFRichTextString(textValue);
HSSFFont font3 = workbook.createFont();
font3.setColor(HSSFColor.BLUE.index);
richString.applyFont(font3);
cell.setCellValue(richString);
}
}
http://blog.sina.com.cn/s/blog_70bcd7c10101cvl4.html