cndavy

导航

 

private void processNumericCell(HSSFRow row, HSSFCell cell, int rowPoint, int colPoint) {
  xmlFileBuffer.append("<td ");
  String styleString = combineCellStyle(getCellStyle(row, cell, rowPoint, colPoint));
  xmlFileBuffer.append(styleString + ">");
  String cellvalue = "";
  if (HSSFDateUtil.isCellDateFormatted(cell)) {
   cellvalue = cell.getDateCellValue().toString(); // 把Date转换成本地格式的字符串
  }
  // 如果是纯数字
  else {
   short dataFormatIndex = cell.getCellStyle().getDataFormat();
   double d = cell.getNumericCellValue();
   DecimalFormat df1;
   switch (dataFormatIndex) {
   case 0:
   case 1:
    df1 = new DecimalFormat("0");
    cellvalue = df1.format(d);
    break;
   case 2:
    df1 = new DecimalFormat("0.00");
    cellvalue = df1.format(d);
    break;
   case 3:
    df1 = new DecimalFormat("#,###");
    cellvalue = df1.format(d);
    break;
   case 4:
    df1 = new DecimalFormat("#,##0.00");
    cellvalue = df1.format(d);
    break;
   default:
    cellvalue = getFormatNumber(d);
    break;
   }
   if (dataFormatIndex < 0 || dataFormatIndex > 0x31 || dataFormatIndex == 0x1f) {
    Date tjnyDate = HSSFDateUtil.getJavaDate(d);
    if (d > 1.00) {
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
     cellvalue = dateFormat.format(tjnyDate);
    } else {
     SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.SIMPLIFIED_CHINESE);
     cellvalue = dateFormat.format(tjnyDate);
    }
   }
  }
  xmlFileBuffer.append(cellvalue);
  xmlFileBuffer.append("</td>");
 }

 

View Code
 1 private void processNumericCell(HSSFRow row, HSSFCell cell, int rowPoint, int colPoint) {
 2         xmlFileBuffer.append("<td ");
 3         String styleString = combineCellStyle(getCellStyle(row, cell, rowPoint, colPoint));
 4         xmlFileBuffer.append(styleString + ">");
 5         String cellvalue = "";
 6         if (HSSFDateUtil.isCellDateFormatted(cell)) {
 7             cellvalue = cell.getDateCellValue().toString(); // 把Date转换成本地格式的字符串
 8         }
 9         // 如果是纯数字
10         else {
11             short dataFormatIndex = cell.getCellStyle().getDataFormat();
12             double d = cell.getNumericCellValue();
13             DecimalFormat df1;
14             switch (dataFormatIndex) {
15             case 0:
16             case 1:
17                 df1 = new DecimalFormat("0");
18                 cellvalue = df1.format(d);
19                 break;
20             case 2:
21                 df1 = new DecimalFormat("0.00");
22                 cellvalue = df1.format(d);
23                 break;
24             case 3:
25                 df1 = new DecimalFormat("#,###");
26                 cellvalue = df1.format(d);
27                 break;
28             case 4:
29                 df1 = new DecimalFormat("#,##0.00");
30                 cellvalue = df1.format(d);
31                 break;
32             default:
33                 cellvalue = getFormatNumber(d);
34                 break;
35             }
36             if (dataFormatIndex < 0 || dataFormatIndex > 0x31 || dataFormatIndex == 0x1f) {
37                 Date tjnyDate = HSSFDateUtil.getJavaDate(d);
38                 if (d > 1.00) {
39                     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
40                     cellvalue = dateFormat.format(tjnyDate);
41                 } else {
42                     SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.SIMPLIFIED_CHINESE);
43                     cellvalue = dateFormat.format(tjnyDate);
44                 }
45             }
46         }
47         xmlFileBuffer.append(cellvalue);
48         xmlFileBuffer.append("</td>");
49     }

 

posted on 2012-09-24 15:14  cndavy  阅读(2655)  评论(0编辑  收藏  举报