java操作EXCEL

private String translateObjectToString(HSSFCell cell){
  String value  = "";
  if(cell!=null){
   if (cell != null)
          {
             // 判断当前Cell的Type
             switch (cell.getCellType())
             {
                // 如果当前Cell的Type为NUMERIC
                case HSSFCell.CELL_TYPE_NUMERIC:                
                case HSSFCell.CELL_TYPE_FORMULA:
                {                  
                     // 取得当前Cell的数值    为了防止将Excel里比较大的数据按科学计数法读出
                    value = NumberFormat.getNumberInstance().format(cell.getNumericCellValue());
                    while (value.indexOf(",") > -1) {
                         value = value.substring(0, value.indexOf(","))+ value.substring(value.indexOf(",") + 1);
                     }
                    break;
                }
                // 如果当前Cell的Type为STRIN
                case HSSFCell.CELL_TYPE_STRING:
                {
                   // 取得当前的Cell字符串
                   value = cell.getStringCellValue().replaceAll("'", "''");
                   break;
                }
                // 默认的Cell值
                default:
                   value = " ";
             }
          }
          else
          {
             value = "";
          }
  }
 
  return value;
 }

你可能感兴趣的:(java,Excel)