From 81480d62561dcb75a1fc968814ace1368fe5181b Mon Sep 17 00:00:00 2001
From: wells.liu <wells.liu@broconcentric.com>
Date: 星期四, 16 七月 2020 11:57:08 +0800
Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071

---
 src/Bro.M071.DBManager/ExcelExportHelper.cs |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/Bro.M071.DBManager/ExcelExportHelper.cs b/src/Bro.M071.DBManager/ExcelExportHelper.cs
index ce6958e..b804e74 100644
--- a/src/Bro.M071.DBManager/ExcelExportHelper.cs
+++ b/src/Bro.M071.DBManager/ExcelExportHelper.cs
@@ -12,20 +12,23 @@
 
     public class ExcelExportSet
     {
-        public List<string> Worksheets { get; set; }
+        public List<string> Worksheets { get; set; } = new List<string>();
 
         /// <summary>
         /// Key锛� Worksheet鐨勫悕绉� Value:Worksheet瀵瑰簲鐨勫垪鍚嶉泦鍚�(key 涓鸿瀵煎嚭鐨勫垪鍚� value 涓哄鍑哄悗鏄剧ず鐨勫垪鍚�)
         /// </summary>
-        public Dictionary<string, Dictionary<string, string>> WorksheetColumns { get; set; }
-        public Dictionary<string, DataTable> WorksheetDataTable { get; set; }
+        public Dictionary<string, Dictionary<string, string>> WorksheetColumns { get; set; } = new Dictionary<string, Dictionary<string, string>>();
 
-        public ExcelExportSet()
-        {
-            Worksheets = new List<string>();
-            WorksheetColumns = new Dictionary<string, Dictionary<string, string>>();
-            WorksheetDataTable = new Dictionary<string, DataTable>();
-        }
+        public Dictionary<string, Dictionary<string, string>> WorksheetRows { get; set; } = new Dictionary<string, Dictionary<string, string>>();
+
+        public Dictionary<string, DataTable> WorksheetDataTable { get; set; } = new Dictionary<string, DataTable>();
+
+        //public ExcelExportSet()
+        //{
+        //    Worksheets = new List<string>();
+        //    WorksheetColumns = new Dictionary<string, Dictionary<string, string>>();
+        //    WorksheetDataTable = new Dictionary<string, DataTable>();
+        //}
 
     }
 
@@ -107,7 +110,7 @@
                     {
                         // autofit width of cells with small content 
                         ExcelRange columnCells = workSheet.Cells[workSheet.Dimension.Start.Row, columnIndex, workSheet.Dimension.End.Row, columnIndex];
-                        int maxLength = columnCells.Max(cell => cell.Value.ToString().Count());
+                        int maxLength = columnCells.Max(cell => (cell.Value ?? "").ToString().Count());
                         if (maxLength < 150)
                         {
                             workSheet.Column(columnIndex).AutoFit();
@@ -258,13 +261,14 @@
         {
             try
             {
-                return obj.ToString();
+                return (obj ?? "").ToString();
             }
             catch (Exception)
             {
                 return "";
             }
         }
-
     }
+
+    
 }

--
Gitblit v1.8.0