浏览代码

完成了GC的全部导出功能

wzp 5 个月前
父节点
当前提交
2f68af1f2a
共有 4 个文件被更改,包括 41 次插入4 次删除
  1. 38
    2
      Back/GC/GCExport.py
  2. 2
    1
      Front/main.py
  3. 1
    1
      Front/modules/ui_functions.py
  4. 二进制
      SQL/1.db

+ 38
- 2
Back/GC/GCExport.py 查看文件

@@ -12,6 +12,8 @@ from openpyxl import Workbook
12 12
 
13 13
 def export_result_data(ui, utf_en, db_path, export_folder):
14 14
     try:
15
+        # 解码 utf_en
16
+        decoded_utf_en = utf_en.decode('utf-8') if isinstance(utf_en, bytes) else utf_en
15 17
         # 连接数据库
16 18
         conn = sqlite3.connect(db_path)
17 19
 
@@ -130,7 +132,7 @@ def export_result_data(ui, utf_en, db_path, export_folder):
130 132
             cell = ws[cell_range.split(':')[0]]
131 133
             cell.alignment = Alignment(horizontal='center', vertical='center')
132 134
         # 保存 Excel 文件
133
-        excel_filename = f"水准测段高差计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
135
+        excel_filename = f"{os.path.splitext(decoded_utf_en)[0]}-成果数据.xlsx"
134 136
         excel_filepath = os.path.join(export_folder, excel_filename)
135 137
         wb.save(excel_filepath)
136 138
 
@@ -160,9 +162,25 @@ def export_initial_data(ui, utf_en, db_path, export_folder):
160 162
         for cell_range in merge_cells:
161 163
             cell = ws[cell_range.split(':')[0]]
162 164
             cell.alignment = Alignment(horizontal='center', vertical='center')
165
+        # 连接数据库
166
+        conn = sqlite3.connect(db_path)
167
+        cursor = conn.cursor()
168
+
169
+        # 查询 GC_Input_Param 表获取 ObservationLevel, Last_ResultName, New_ResultName, Ms_Station 字段
170
+        query_observation_level = "SELECT ObservationLevel, Last_ResultName, New_ResultName, Ms_Station FROM GC_Input_Param WHERE TableName=?"
171
+        cursor.execute(query_observation_level, (utf_en,))
172
+        result = cursor.fetchone()
173
+        if result:
174
+            observation_level, last_result_name, new_result_name, ms_station = result
175
+        else:
176
+            observation_level = "未找到"
177
+            last_result_name = "未找到"
178
+            new_result_name = "未找到"
179
+            ms_station = "未找到"
163 180
 
164 181
         # 填写表头信息
165 182
         ws['A1'] = '观测等级'
183
+        ws['C1'] = observation_level  # 将 ObservationLevel 写入 C1 单元格
166 184
         ws['A2'] = '序号'
167 185
         ws['B2'] = '起点'
168 186
         ws['C2'] = '终点'
@@ -175,6 +193,14 @@ def export_initial_data(ui, utf_en, db_path, export_folder):
175 193
         ws['I2'] = '高差(m)'
176 194
         ws['J2'] = '路线长(km)'
177 195
 
196
+        # 写入 Last_ResultName, New_ResultName, Ms_Station 到相应的单元格
197
+        ws['D1'] = last_result_name
198
+        ws['I1'] = new_result_name
199
+        ws['H1'] = ms_station
200
+
201
+        # 设置 H1 单元格的数值格式为保留两位小数
202
+        ws['H1'].number_format = '0.00'
203
+
178 204
         # 连接数据库
179 205
         conn = sqlite3.connect(db_path)
180 206
         cursor = conn.cursor()
@@ -240,7 +266,7 @@ def export_initial_data(ui, utf_en, db_path, export_folder):
240 266
         QMessageBox.critical(ui, '错误', f'导出初始数据过程中发生错误: {str(e)}')
241 267
 
242 268
 
243
-def main_function(ui, utf_en, db_path):
269
+def main_function_initial(ui, utf_en, db_path):
244 270
     # 获取应用的安装目录
245 271
     app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
246 272
     export_folder = os.path.join(app_install_dir, 'Export')
@@ -251,5 +277,15 @@ def main_function(ui, utf_en, db_path):
251 277
 
252 278
     # 调用导出初始数据函数
253 279
     export_initial_data(ui, utf_en, db_path, export_folder)
280
+
281
+
282
+def main_function_result(ui, utf_en, db_path):
283
+    # 获取应用的安装目录
284
+    app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
285
+    export_folder = os.path.join(app_install_dir, 'Export')
286
+
287
+    # 如果 Export 文件夹不存在,则创建它
288
+    if not os.path.exists(export_folder):
289
+        os.makedirs(export_folder)
254 290
     # 调用导出结果函数
255 291
     export_result_data(ui, utf_en, db_path, export_folder)

+ 2
- 1
Front/main.py 查看文件

@@ -289,7 +289,8 @@ class ElTree(QWidget):
289 289
 
290 290
         # 根据父节点名称确定导出操作
291 291
         if parent_name == '水准测段高差稳定计算':
292
-            GCExport.main_function(self, tablename_utf8, dbpath)
292
+            GCExport.main_function_initial(self, tablename_utf8, dbpath)
293
+            GCExport.main_function_result(self, tablename_utf8, dbpath)
293 294
         elif parent_name == '控制网复测平面基准计算':
294 295
             GSExport.main_function(self, dbpath, tablename)
295 296
         elif parent_name == '平面控制网稳定性计算':

+ 1
- 1
Front/modules/ui_functions.py 查看文件

@@ -357,7 +357,7 @@ class UIFunctions(MainWindow):
357 357
         excelname = os.path.basename(file_path)  # 文件名
358 358
         utf_en = excelname.encode('utf-8')  # 转换文件名为utf-8编码形式
359 359
         if current_text == "水准测段高差稳定计算":
360
-            GCExport.main_function(self, utf_en, db_path)
360
+            GCExport.main_function_result(self, utf_en, db_path)
361 361
         elif current_text == "控制网复测平面基准计算":
362 362
             GSExport.main_function(self, db_path, excelname)
363 363
         elif current_text == "平面控制网稳定性计算":

二进制
SQL/1.db 查看文件


正在加载...
取消
保存