首页 > 其他 > 详细

NPOI 导入为table 处理excel 格式问题

时间:2018-07-06 12:45:55      阅读:198      评论:0      收藏:0      [点我收藏+]
ICell cell = row.GetCell(j);
                        if (!cell.isDbNullOrNull())
                        {
                            switch (cell.CellType)
                            {
                                case CellType.Blank:
                                    dataRow[j] = string.Empty;
                                    break;
                                case CellType.Boolean:
                                    dataRow[j] = cell.BooleanCellValue;
                                    break;
                                case CellType.Numeric:
                                    if (DateUtil.IsCellDateFormatted(cell))//日期
                                    {
                                        dataRow[j] = cell.DateCellValue;
                                    }
                                    else
                                    {
                                        dataRow[j] = cell.NumericCellValue;
                                    }
                                    break;
                                case CellType.String:
                                    dataRow[j] = cell.StringCellValue.Trim();
                                    break;
                                case CellType.Error:
                                    dataRow[j] = cell.ErrorCellValue;
                                    break;
                                case CellType.Formula://公式
                                    try
                                    {
                                        HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
                                        e.EvaluateInCell(cell);
                                        dataRow[j] = cell.ToString();
                                    }
                                    catch
                                    {
                                        if (DateUtil.IsCellDateFormatted(cell))//日期
                                        {
                                            dataRow[j] = cell.DateCellValue;
                                        }
                                        else
                                        {
                                            dataRow[j] = cell.NumericCellValue;
                                        }
                                    }
                                    break;
                                default:
                                    dataRow[j] = cell.ToString();
                                    break;
                            }
                        }

 

NPOI 导入为table 处理excel 格式问题

原文:https://www.cnblogs.com/itclw/p/9272959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!