Przeglądaj źródła

sljdjs
Signed-off-by: binren <zhangbr@elab-plus.com>

binren 4 lat temu
rodzic
commit
84df120dd0
1 zmienionych plików z 17 dodań i 18 usunięć
  1. 17 18
      xlwt_util.py

+ 17 - 18
xlwt_util.py

@@ -145,19 +145,23 @@ class XlwtUtil(object):
         return new_path
 
     def create_excel(self, data_dict, time_rang, task_key):
+        self.default_style = self.set_style('Times New Roman',
+                       200,
+                       bold=False,
+                       format_str='', align='')
         result = []
         for key in data_dict.keys():
             self.wb = xlwt.Workbook()
             values = data_dict.get(key)
-            data_1 = values.get(1)
-            data_2 = values.get(2)
-            data_3 = values.get(3)
-            data_4 = values.get(4)
-            data_5 = values.get(5)
-            data_6 = values.get(6)
-            data_7 = values.get(7)
-            data_8 = values.get(8)
-            mail = values.get(0)
+            data_1 = values.get('1')
+            data_2 = values.get('2')
+            data_3 = values.get('3')
+            data_4 = values.get('4')
+            data_5 = values.get('5')
+            data_6 = values.get('6')
+            data_7 = values.get('7')
+            data_8 = values.get('8')
+            mail = values.get('0')
             start_row = 0
             global title
             global sheet_name
@@ -190,6 +194,7 @@ class XlwtUtil(object):
             for col in [1, 3, 5]:
                 for row in [1, 2, 3, 4]:
                     ws.col(col).width = 150 * 30  # 定义列宽
+                    print(data_1)
                     ws.write(row, col, str(data_1[col_index]),
                     style=self.set_style('Times New Roman',
                                            200,
@@ -331,10 +336,7 @@ class XlwtUtil(object):
                     value = 0
                 ws.col(col).width = 150 * 30  # 定义列宽
                 ws.write(start_row, col, str(value),
-                style=self.set_style('Times New Roman',
-                                       200,
-                                       bold=False,
-                                       format_str='', align=''))
+                style=self.default_style)
             start_row += 1
 
     def sceptical_insert_cells(self, ws, data, start_row, cols):
@@ -343,16 +345,13 @@ class XlwtUtil(object):
             for col in cols:
                 ws.col(col).width = 150 * 30  # 定义列宽
                 ws.write(start_row, col, str(x[col_index]),
-                style=self.set_style('Times New Roman',
-                                       200,
-                                       bold=False,
-                                       format_str='', align=''))
+                style=self.default_style)
                 col_index += 1
             start_row += 1
 
 
 if __name__ == '__main__':
     xu = XlwtUtil()
-    data = {}
+    data ={}
     for x in xu.create_excel(data, ['2020-03-12', '2020-03-13'], 2):
         print(x)