fhx
2021-07-19 c6eec82a790b6dc9c1d74556a52cd891a2017e8c
提交 | 用户 | age
5c5945 1 package com.hx.util;
E 2
3 import com.hx.exception.TipsException;
cac339 4 import org.apache.poi.POIXMLDocument;
5c5945 5 import org.apache.poi.hssf.usermodel.*;
cac339 6 import org.apache.poi.openxml4j.opc.OPCPackage;
C 7 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
5c5945 8 import org.apache.poi.ss.usermodel.Cell;
cac339 9 import org.apache.poi.ss.usermodel.Row;
C 10 import org.apache.poi.ss.usermodel.Sheet;
11 import org.apache.poi.ss.usermodel.Workbook;
c6eec8 12 import org.apache.poi.xssf.usermodel.XSSFCell;
F 13 import org.apache.poi.xssf.usermodel.XSSFRow;
14 import org.apache.poi.xssf.usermodel.XSSFSheet;
cac339 15 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
5c5945 16 import org.springframework.web.multipart.MultipartFile;
c6eec8 17
F 18 import java.io.*;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.Map;
5c5945 25
E 26
27 /**
cac339 28  *
5c5945 29  * @author hjr
E 30  */
31 public final class ExcelUtil {
32
33     /**
34      * @param excelName
35      *         文件名称
36      * @param outPath
37      *             保存路径
38      * @param headList
39      *        Excel文件Head标题集合
40      * @param fieldList
41      *        Excel文件Field标题集合 根据field来寻找位置填充表格
42      * @param dataList
43      *        Excel文件数据内容部分
44      * @throws Exception
45      */
46     public static String createExcel(String outPath, String excelName,
cac339 47                                      String[] headList, String[] fieldList,
C 48                                      List<Map<String, Object>> dataList) throws Exception {
5c5945 49
E 50         String filePath = null;
51         // 创建新的Excel 工作簿
52         HSSFWorkbook workbook = new HSSFWorkbook();
53
54         // 在Excel工作簿中建一工作表,其名为缺省值
55         // 如要新建一名为"效益指标"的工作表,其语句为:
56         // HSSFSheet sheet = workbook.createSheet("效益指标");
57         HSSFSheet sheet = workbook.createSheet();
58         // 在索引0的位置创建行(最顶端的行)
59         HSSFRow row = sheet.createRow(0);
60         // ===============================================================
61         for (int i = 0; i < headList.length; i++) {
62
63             // 在索引0的位置创建单元格(左上端)
64             HSSFCell cell = row.createCell(i);
65             // 定义单元格为字符串类型
66             cell.setCellType(HSSFCell.CELL_TYPE_STRING);
67             // 在单元格中输入一些内容
68             cell.setCellValue(headList[i]);
69         }
70         // ===============================================================
71         if (dataList != null) {
72             for (int n = 0; n < dataList.size(); n++) {
73                 // 在索引1的位置创建行
74                 HSSFRow row_value = sheet.createRow(n + 1);
75                 Map<String, Object> dataMap = dataList.get(n);
76                 // ===============================================================
77                 for (int i = 0; i < fieldList.length; i++) {
78                     // 在索引0的位置创建单元格(左上端)
79                     HSSFCell cell = row_value.createCell(i);
80                     // 定义单元格为字符串类型
81                     cell.setCellType(HSSFCell.CELL_TYPE_STRING);
82                     // 在单元格中输入一些内容
83                     cell.setCellValue(objToString(dataMap.get(fieldList[i])));
84                 }
85                 // ===============================================================
86             }
87         }
88
89         // 新建一输出文件流
c6eec8 90         File file = SimpleTool.createFile(outPath, excelName);
5c5945 91         FileOutputStream fOut = new FileOutputStream(file);
E 92         // 把相应的Excel 工作簿存盘
93         workbook.write(fOut);
94         fOut.flush();
95         // 操作结束,关闭文件
96         fOut.close();
97
98         if(outPath.endsWith("/")){
99             filePath = outPath + excelName;
100         }else{
101             filePath = outPath +"/"+ excelName;
102         }
103         return filePath;
104     }
105
db7fc9 106     /**生成临时文件
C 107      * @param headList
108      *        Excel文件Head标题集合
109      * @param fieldList
110      *        Excel文件Field标题集合 根据field来寻找位置填充表格
111      * @param dataList
112      *        Excel文件数据内容部分
113      * @throws Exception
114      */
115     public static File createExcel(String[] headList, String[] fieldList,
cac339 116                                    List<Map<String, Object>> dataList) throws Exception {
db7fc9 117         File file = File.createTempFile("temp", ".xls");
C 118         try{
119             // 创建新的Excel 工作簿
120             HSSFWorkbook workbook = new HSSFWorkbook();
121
122             // 在Excel工作簿中建一工作表,其名为缺省值
123             // 如要新建一名为"效益指标"的工作表,其语句为:
124             // HSSFSheet sheet = workbook.createSheet("效益指标");
125             HSSFSheet sheet = workbook.createSheet();
126             // 在索引0的位置创建行(最顶端的行)
127             HSSFRow row = sheet.createRow(0);
128             // ===============================================================
129             for (int i = 0; i < headList.length; i++) {
130
131                 // 在索引0的位置创建单元格(左上端)
132                 HSSFCell cell = row.createCell(i);
133                 // 定义单元格为字符串类型
134                 cell.setCellType(HSSFCell.CELL_TYPE_STRING);
135                 // 在单元格中输入一些内容
136                 cell.setCellValue(headList[i]);
137             }
138             // ===============================================================
139             if (dataList != null) {
140                 for (int n = 0; n < dataList.size(); n++) {
141                     // 在索引1的位置创建行
142                     HSSFRow row_value = sheet.createRow(n + 1);
143                     Map<String, Object> dataMap = dataList.get(n);
144                     // ===============================================================
145                     for (int i = 0; i < fieldList.length; i++) {
146                         // 在索引0的位置创建单元格(左上端)
147                         HSSFCell cell = row_value.createCell(i);
148                         // 定义单元格为字符串类型
149                         cell.setCellType(HSSFCell.CELL_TYPE_STRING);
150                         // 在单元格中输入一些内容
151                         cell.setCellValue(objToString(dataMap.get(fieldList[i])));
152                     }
153                     // ===============================================================
154                 }
155             }
156
157             // 新建一输出文件流
158             FileOutputStream fOut = new FileOutputStream(file);
159             // 把相应的Excel 工作簿存盘
160             workbook.write(fOut);
161             fOut.flush();
162             // 操作结束,关闭文件
163             fOut.close();
164         }catch (Exception e){
165
166         }finally {
167             file.deleteOnExit();
168         }
169         return file;
170     }
171
49f28b 172     /**生成临时文件
C 173      * @param headList
174      *        Excel文件Head标题集合
175      * @param fieldList
176      *        Excel文件Field标题集合 根据field来寻找位置填充表格
177      * @param dataList
178      *        Excel文件数据内容部分
179      * @throws Exception
180      */
181     public static File createExcel(String[] headList, String[] fieldList, List<Map<String, Object>> dataList
182             ,Integer height,Integer width) throws Exception {
183         File file = File.createTempFile("temp", ".xls");
184         try{
185
186             if(height == null){
187                 height = 450;
188             }
189             if(width == null){
190                 width = 5000;
191             }
192             // 创建新的Excel 工作簿
193             HSSFWorkbook workbook = new HSSFWorkbook();
194
195             //合并的单元格样式
196             HSSFCellStyle boderStyle = workbook.createCellStyle();
197             //垂直居中
198             boderStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
199             boderStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
200
201             // 在Excel工作簿中建一工作表,其名为缺省值
202             // 如要新建一名为"效益指标"的工作表,其语句为:
203             // HSSFSheet sheet = workbook.createSheet("效益指标");
204             HSSFSheet sheet = workbook.createSheet();
205             // 在索引0的位置创建行(最顶端的行)
206             HSSFRow row = sheet.createRow(0);
207             // ===============================================================
208             for (int i = 0; i < headList.length; i++) {
209                 //高度
210                 row.setHeight(height.shortValue());
211                 sheet.setColumnWidth(i,width);
212                 // 在索引0的位置创建单元格(左上端)
213                 HSSFCell cell = row.createCell(i);
214                 // 定义单元格为字符串类型
215                 cell.setCellType(HSSFCell.CELL_TYPE_STRING);
216                 // 在单元格中输入一些内容
217                 cell.setCellValue(headList[i]);
218                 cell.setCellStyle(boderStyle);
219             }
220             // ===============================================================
221             if (dataList != null) {
222                 for (int n = 0; n < dataList.size(); n++) {
223                     // 在索引1的位置创建行
224                     HSSFRow row_value = sheet.createRow(n + 1);
225                     row_value.setHeight(height.shortValue());
226                     Map<String, Object> dataMap = dataList.get(n);
227                     // ===============================================================
228                     for (int i = 0; i < fieldList.length; i++) {
229                         // 在索引0的位置创建单元格(左上端)
230                         sheet.setColumnWidth(i,width);
231                         HSSFCell cell = row_value.createCell(i);
232                         // 定义单元格为字符串类型
233                         cell.setCellType(HSSFCell.CELL_TYPE_STRING);
234                         // 在单元格中输入一些内容
235                         cell.setCellValue(objToString(dataMap.get(fieldList[i])));
236                         cell.setCellStyle(boderStyle);
237                     }
238                     // ===============================================================
239                 }
240             }
241
242             // 新建一输出文件流
243             FileOutputStream fOut = new FileOutputStream(file);
244             // 把相应的Excel 工作簿存盘
245             workbook.write(fOut);
246             fOut.flush();
247             // 操作结束,关闭文件
248             fOut.close();
249         }catch (Exception e){
250
251         }finally {
252             file.deleteOnExit();
253         }
254         return file;
255     }
256
db7fc9 257
5c5945 258     private static String objToString(Object obj) {
E 259         if (obj == null) {
260             return "";
261         } else {
262             if (obj instanceof String) {
263                 return (String) obj;
264             } else if (obj instanceof Date) {
265                 return null;// DateUtil.dateToString((Date)
cac339 266                 // obj,DateUtil.DATESTYLE_SHORT_EX);
5c5945 267             } else {
E 268                 return obj.toString();
269             }
270         }
271     }
272
273     /**
c6eec8 274      * 读取Excel数据
F 275      * @param file
276      * @param header
277      * @return
278      * @throws Exception
279      */
280     public static List<List<String>> readExcelData(MultipartFile file, boolean header) throws Exception {
281
282         String fileName = file.getOriginalFilename();
283         if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
284             throw new TipsException("上传文件格式不正确");
285         }
286
287         //判断不同格式处理方法不同
288         if(fileName.matches("^.+\\.(?i)(xls)$")){
289             //xls格式使用HSSF
290             return readExcelByeFileData(file, header);
291         }else{
292             //xlsx格式使用XSSF
293             return readExcelByeFileDataToXSSF(file, header);
294         }
295     }
296
297     /**
5c5945 298      * 读取 Excel文件内容
E 299      *
300      * @param file
301      * @param header 是否包括表头
302      * @return
303      * @throws Exception
304      */
305     public static List<List<String>> readExcelByeFileData(MultipartFile file, boolean header) throws Exception {
306
307         String fileName = file.getOriginalFilename();
308         if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
309             throw new TipsException("上传文件格式不正确");
310         }
311
312         // 结果集
313         List<List<String>> list = new ArrayList<>();
314
315         HSSFWorkbook hssfworkbook = new HSSFWorkbook(file.getInputStream());
316
317         // 遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数
318         for(int s=0;s<hssfworkbook.getNumberOfSheets();s++) {
319             HSSFSheet hssfsheet = hssfworkbook.getSheetAt(s);
320             int col = 0;
321             // 遍历该行所有的行,j表示行数 getPhysicalNumberOfRows行的总数 去除标题
322             for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) {
323                 HSSFRow hssfrow = hssfsheet.getRow(j);
324                 if(hssfrow!=null){
325                     if(j == 0) {
326                         col = hssfrow.getPhysicalNumberOfCells();
327                         if(!header) {
328                             //不包括表头
329                             continue;
330                         }
331                     }
332                     // 单行数据
333                     List<String> arrayString = new ArrayList<>();
334                     for (int i = 0; i < col; i++) {
335                         HSSFCell cell = hssfrow.getCell(i);
336                         if (cell == null) {
337                             arrayString.add("");
338                         } else if (cell.getCellType() == 0) {
339                             // arrayString[i] = new Double(cell.getNumericCellValue()).toString();
340                             if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
341                                 short format = cell.getCellStyle().getDataFormat();
342                                 if(format == 14 || format == 31 || format == 57 || format == 58){
343                                     //日期(中文时间格式的)
344                                     Date d = cell.getDateCellValue();
345                                     DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
346                                     // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
347                                     arrayString.add(formater.format(d));
348                                     //arrayString[i] = formater.format(d);
349                                 }else if (HSSFDateUtil.isCellDateFormatted(cell)) {
350                                     Date d = cell.getDateCellValue();
351                                     //DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
352                                     DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
353                                     arrayString.add(formater.format(d));
354                                     //arrayString[i] = formater.format(d);
355                                 } else {
356                                     if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){
357                                         arrayString.add(cell.getStringCellValue());
358                                         //arrayString[i] =cell.getStringCellValue();
359                                     }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){
360                                         arrayString.add(cell.getCellFormula());
361                                         //arrayString[i] =cell.getCellFormula();
362                                     }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){
363                                         HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
364                                         arrayString.add(dataFormatter.formatCellValue(cell));
365                                         //arrayString[i] =dataFormatter.formatCellValue(cell);
366                                     }
367                                 }
368                             }
369                         } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){
370                             arrayString.add("");
371                             //arrayString[i] = "";
372                         } else { // 如果EXCEL表格中的数据类型为字符串型
373                             arrayString.add(cell.getStringCellValue().trim());
374                             //arrayString[i] = cell.getStringCellValue().trim();
375                         }
376                     }
377                     list.add(arrayString);
378                 }
379             }
380         }
381         return list;
382     }
383
c6eec8 384     /**
F 385      * 读取 Excel文件内容
386      *
387      * @param file
388      * @param header 是否包括表头
389      * @return
390      * @throws Exception
391      */
392     public static List<List<String>> readExcelByeFileDataToXSSF(MultipartFile file, boolean header) throws Exception {
393
394         String fileName = file.getOriginalFilename();
395         if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
396             throw new TipsException("上传文件格式不正确");
397         }
398
399         // 结果集
400         List<List<String>> list = new ArrayList<>();
401
402         XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file.getInputStream());
403
404         // 遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数
405         for(int s=0;s<xssfWorkbook.getNumberOfSheets();s++) {
406             XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(s);
407             int col = 0;
408             // 遍历该行所有的行,j表示行数 getPhysicalNumberOfRows行的总数 去除标题
409             for (int j = 0; j < xssfSheet.getPhysicalNumberOfRows(); j++) {
410                 XSSFRow xssfrow = xssfSheet.getRow(j);
411                 if(xssfrow!=null){
412                     if(j == 0) {
413                         col = xssfrow.getPhysicalNumberOfCells();
414                         if(!header) {
415                             //不包括表头
416                             continue;
417                         }
418                     }
419                     // 单行数据
420                     List<String> arrayString = new ArrayList<>();
421                     for (int i = 0; i < col; i++) {
422                         XSSFCell cell = xssfrow.getCell(i);
423                         if (cell == null) {
424                             arrayString.add("");
425                         } else if (cell.getCellType() == 0) {
426                             // arrayString[i] = new Double(cell.getNumericCellValue()).toString();
427                             if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
428                                 short format = cell.getCellStyle().getDataFormat();
429                                 if(format == 14 || format == 31 || format == 57 || format == 58){
430                                     //日期(中文时间格式的)
431                                     Date d = cell.getDateCellValue();
432                                     DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
433                                     // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
434                                     arrayString.add(formater.format(d));
435                                     //arrayString[i] = formater.format(d);
436                                 }else if (HSSFDateUtil.isCellDateFormatted(cell)) {
437                                     Date d = cell.getDateCellValue();
438                                     //DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
439                                     DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
440                                     arrayString.add(formater.format(d));
441                                     //arrayString[i] = formater.format(d);
442                                 } else {
443                                     if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){
444                                         arrayString.add(cell.getStringCellValue());
445                                         //arrayString[i] =cell.getStringCellValue();
446                                     }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){
447                                         arrayString.add(cell.getCellFormula());
448                                         //arrayString[i] =cell.getCellFormula();
449                                     }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){
450                                         HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
451                                         arrayString.add(dataFormatter.formatCellValue(cell));
452                                         //arrayString[i] =dataFormatter.formatCellValue(cell);
453                                     }
454                                 }
455                             }
456                         } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){
457                             arrayString.add("");
458                             //arrayString[i] = "";
459                         } else { // 如果EXCEL表格中的数据类型为字符串型
460                             arrayString.add(cell.getStringCellValue().trim());
461                             //arrayString[i] = cell.getStringCellValue().trim();
462                         }
463                     }
464                     list.add(arrayString);
465                 }
466             }
467         }
468         return list;
469     }
470
cac339 471
C 472     /**判断excel的版本*/
473     public static Workbook create(InputStream inp) throws Exception {
474         if (!inp.markSupported()) {
475             inp = new PushbackInputStream(inp, 8);
476         }
477         if (POIFSFileSystem.hasPOIFSHeader(inp)) {
478             return new HSSFWorkbook(inp);
479         }
480         if (POIXMLDocument.hasOOXMLHeader(inp)) {
481             return new XSSFWorkbook(OPCPackage.open(inp));
482         }
483         throw new IllegalArgumentException("你的excel版本目前poi解析不了");
484     }
485
486     /**读取excel文件,兼容2003和2007
487      * 通过流读取Excel文件
488      * @return
489      * @throws Exception
490      */
491     public static List<List<String>> getExcelDataCompatible(MultipartFile file,boolean header) throws Exception {
492         try {
493
494             String fileName = file.getOriginalFilename();
495             if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
496                 throw new TipsException("上传文件格式不正确");
497             }
498
499             // 结果集
500             List<List<String>> list = new ArrayList<>();
501             Workbook book = create(new BufferedInputStream(file.getInputStream()));
502
503             // 遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数
504             for(int s=0;s<book.getNumberOfSheets();s++) {
505                 Sheet hssfsheet = book.getSheetAt(s);
506                 int col = 0;
507                 // 遍历该行所有的行,j表示行数 getPhysicalNumberOfRows行的总数 去除标题
508                 for (int j = 0; j < hssfsheet.getPhysicalNumberOfRows(); j++) {
509                     Row hssfrow = hssfsheet.getRow(j);
510                     if(hssfrow!=null){
511                         if(j == 0) {
512                             col = hssfrow.getPhysicalNumberOfCells();
513                             if(!header) {
514                                 //不包括表头
515                                 continue;
516                             }
517                         }
518                         // 单行数据
519                         List<String> arrayString = new ArrayList<>();
520                         for (int i = 0; i < col; i++) {
521                             Cell cell = hssfrow.getCell(i);
522                             if (cell == null) {
523                                 arrayString.add("");
524                             } else if (cell.getCellType() == 0) {
525                                 // arrayString[i] = new Double(cell.getNumericCellValue()).toString();
526                                 if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
527                                     short format = cell.getCellStyle().getDataFormat();
528                                     if(format == 14 || format == 31 || format == 57 || format == 58){
529                                         //日期(中文时间格式的)
530                                         Date d = cell.getDateCellValue();
531                                         DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
532                                         // DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
533                                         arrayString.add(formater.format(d));
534                                         //arrayString[i] = formater.format(d);
535                                     }else if (HSSFDateUtil.isCellDateFormatted(cell)) {
536                                         Date d = cell.getDateCellValue();
537                                         //DateFormat formater = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
538                                         DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
539                                         arrayString.add(formater.format(d));
540                                         //arrayString[i] = formater.format(d);
541                                     } else {
542                                         if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){
543                                             arrayString.add(cell.getStringCellValue());
544                                             //arrayString[i] =cell.getStringCellValue();
545                                         }else if(HSSFCell.CELL_TYPE_FORMULA==cell.getCellType()){
546                                             arrayString.add(cell.getCellFormula());
547                                             //arrayString[i] =cell.getCellFormula();
548                                         }else if(HSSFCell.CELL_TYPE_NUMERIC== cell.getCellType()){
549                                             HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
550                                             arrayString.add(dataFormatter.formatCellValue(cell));
551                                             //arrayString[i] =dataFormatter.formatCellValue(cell);
552                                         }
553                                     }
554                                 }
555                             } else if(cell.getCellType() == Cell.CELL_TYPE_BLANK){
556                                 arrayString.add("");
557                                 //arrayString[i] = "";
558                             } else { // 如果EXCEL表格中的数据类型为字符串型
559                                 arrayString.add(cell.getStringCellValue().trim());
560                                 //arrayString[i] = cell.getStringCellValue().trim();
561                             }
562                         }
563                         list.add(arrayString);
564                     }
565                 }
566             }
567             return list;
568         } catch (Exception e) {
569             e.printStackTrace();
570         }
571         return null;
572     }
573
574     private static String getCellVal(Cell cell) {
575         if (null == cell) {
576             return "";
577         }
578         switch (cell.getCellType()) {
579             // 数字
580             case HSSFCell.CELL_TYPE_NUMERIC:
581                 // 日期格式的处理
582                 if (HSSFDateUtil.isCellDateFormatted(cell)) {
583                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
584                     return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString();
585                 }
586                 return String.valueOf(cell.getNumericCellValue());
587             // 字符串
588             case HSSFCell.CELL_TYPE_STRING:
589                 return cell.getStringCellValue();
590             // 公式
591             case HSSFCell.CELL_TYPE_FORMULA:
592                 return cell.getCellFormula();
593             // 空白
594             case HSSFCell.CELL_TYPE_BLANK:
595                 return "";
596             case HSSFCell.CELL_TYPE_BOOLEAN:
597                 return cell.getBooleanCellValue() + "";
598             // 错误类型
599             case HSSFCell.CELL_TYPE_ERROR:
600                 return cell.getErrorCellValue() + "";
601             default:
602                 break;
603         }
604         return "";
605     }
606
607 }