Переглянути джерело

完善了GS,WD的文件导出,所有的文件导出路径,都是选择计算的文件所在的文件路径。

wzp 10 місяці тому
джерело
коміт
9f1d1af48c
6 змінених файлів з 158 додано та 134 видалено
  1. 3
    1
      .gitignore
  2. 7
    3
      Back/GC/GCExport.py
  3. 79
    70
      Back/GS/GSExport.py
  4. 64
    54
      Back/WD/WDExport.py
  5. 5
    6
      Front/modules/ui_functions.py
  6. BIN
      SQL/1.db

+ 3
- 1
.gitignore Переглянути файл

1
 __pycache__/
1
 __pycache__/
2
 .git/
2
 .git/
3
-.pyc
3
+.pyc
4
+.idea/
5
+*.xml

+ 7
- 3
Back/GC/GCExport.py Переглянути файл

35
                 conn.close()
35
                 conn.close()
36
                 return
36
                 return
37
 
37
 
38
+        # 删除 TableName 列
39
+        if 'TableName' in df.columns:
40
+            df.drop(columns=['TableName'], inplace=True)
38
         # new HDiff 保留小数点后6位
41
         # new HDiff 保留小数点后6位
39
         if 'New_HDiff' in df.columns:
42
         if 'New_HDiff' in df.columns:
40
             df['New_HDiff'] = df['New_HDiff'].round(6)
43
             df['New_HDiff'] = df['New_HDiff'].round(6)
50
 
53
 
51
         # 重命名指定的列
54
         # 重命名指定的列
52
         column_mapping = {
55
         column_mapping = {
53
-            'TableName': '文件名',
54
             'New_ID': '序号',
56
             'New_ID': '序号',
55
             'New_ResultName': '结果期数',
57
             'New_ResultName': '结果期数',
56
             'New_SPName': '起点',
58
             'New_SPName': '起点',
101
             if cell_value == '变形':
103
             if cell_value == '变形':
102
                 for col in range(1, ws.max_column + 1):
104
                 for col in range(1, ws.max_column + 1):
103
                     ws.cell(row=row, column=col).font = red_font
105
                     ws.cell(row=row, column=col).font = red_font
104
-
106
+        # 设置列宽
107
+        ws.column_dimensions['E'].width = 12
108
+        ws.column_dimensions['F'].width = 12
105
         # 保存 Excel 文件
109
         # 保存 Excel 文件
106
         excel_filename = f"水准测段高差计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
110
         excel_filename = f"水准测段高差计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
107
         excel_filepath = os.path.join(export_folder, excel_filename)
111
         excel_filepath = os.path.join(export_folder, excel_filename)
108
         wb.save(excel_filepath)
112
         wb.save(excel_filepath)
109
 
113
 
110
-        QMessageBox.information(ui, '成功', f'数据库已成功导出到 {excel_filepath}')
114
+        QMessageBox.information(ui, '成功', f'成果文件已成功导出到 {export_folder}')
111
     except Exception as e:
115
     except Exception as e:
112
         QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
116
         QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
113
     finally:
117
     finally:

+ 79
- 70
Back/GS/GSExport.py Переглянути файл

1
 import openpyxl
1
 import openpyxl
2
 import sqlite3
2
 import sqlite3
3
 import os
3
 import os
4
+import time
4
 from openpyxl.styles import Alignment
5
 from openpyxl.styles import Alignment
6
+from PySide6.QtWidgets import QMessageBox
7
+
5
 
8
 
6
 def Arrange_Data1(list1):
9
 def Arrange_Data1(list1):
7
-    #最终return的
10
+    # 最终return的
8
     list2 = []
11
     list2 = []
9
     for data1 in list1:
12
     for data1 in list1:
10
-        #点名
11
-        #存每一行的数据
13
+        # 点名
14
+        # 存每一行的数据
12
         resultlist = []
15
         resultlist = []
13
         pn = data1[0].decode('utf-8')
16
         pn = data1[0].decode('utf-8')
14
         resultlist.append(pn)
17
         resultlist.append(pn)
17
         resultlist.append(data1[3])
20
         resultlist.append(data1[3])
18
         resultlist.append(data1[4])
21
         resultlist.append(data1[4])
19
         resultlist.append(data1[5])
22
         resultlist.append(data1[5])
20
-        #判定
23
+        # 判定
21
         an1 = data1[6].decode('utf-8')
24
         an1 = data1[6].decode('utf-8')
22
         resultlist.append(an1)
25
         resultlist.append(an1)
23
-        #两个结果名字(旧新)
26
+        # 两个结果名字(旧新)
24
         name1 = data1[7].decode('utf-8')
27
         name1 = data1[7].decode('utf-8')
25
         resultlist.append(name1)
28
         resultlist.append(name1)
26
         name2 = data1[8].decode('utf-8')
29
         name2 = data1[8].decode('utf-8')
28
         list2.append(resultlist)
31
         list2.append(resultlist)
29
     return list2
32
     return list2
30
 
33
 
31
-#复测成果表
34
+
35
+# 复测成果表
32
 def Arrange_Data2(list1):
36
 def Arrange_Data2(list1):
33
-    #最终return的
37
+    # 最终return的
34
     list2 = []
38
     list2 = []
35
     for data1 in list1:
39
     for data1 in list1:
36
-        #点名
37
-        #存每一行的数据
40
+        # 点名
41
+        # 存每一行的数据
38
         resultlist = []
42
         resultlist = []
39
         pn = data1[0].decode('utf-8')
43
         pn = data1[0].decode('utf-8')
40
         resultlist.append(pn)
44
         resultlist.append(pn)
45
         resultlist.append(data1[5])
49
         resultlist.append(data1[5])
46
         resultlist.append(data1[6])
50
         resultlist.append(data1[6])
47
         resultlist.append(data1[7])
51
         resultlist.append(data1[7])
48
-        #判定
52
+        # 判定
49
         an1 = data1[8].decode('utf-8')
53
         an1 = data1[8].decode('utf-8')
50
         resultlist.append(an1)
54
         resultlist.append(an1)
51
-        #两个结果名字(旧新)
55
+        # 两个结果名字(旧新)
52
         name1 = data1[9].decode('utf-8')
56
         name1 = data1[9].decode('utf-8')
53
         resultlist.append(name1)
57
         resultlist.append(name1)
54
         name2 = data1[10].decode('utf-8')
58
         name2 = data1[10].decode('utf-8')
55
         resultlist.append(name2)
59
         resultlist.append(name2)
56
         list2.append(resultlist)
60
         list2.append(resultlist)
57
-    
61
+
58
     return list2
62
     return list2
59
 
63
 
60
-def openpyxl_write(outpath,dbpath,filename):
64
+
65
+def openpyxl_write(file_name, dbpath, filename):
61
     utf_en = filename.encode('utf-8')
66
     utf_en = filename.encode('utf-8')
62
-    #新建对应的excel
67
+    # 新建对应的excel
63
     wb = openpyxl.Workbook()
68
     wb = openpyxl.Workbook()
64
     ws2 = wb.create_sheet('复测成果表')
69
     ws2 = wb.create_sheet('复测成果表')
65
     ws1 = wb.create_sheet('复测基准归算表')
70
     ws1 = wb.create_sheet('复测基准归算表')
67
     ws5 = wb['Sheet']
72
     ws5 = wb['Sheet']
68
     wb.remove(ws5)
73
     wb.remove(ws5)
69
 
74
 
70
-    #w1部分(基准归算表)
71
-    #提取数据
75
+    # w1部分(基准归算表)
76
+    # 提取数据
72
     db = sqlite3.connect(dbpath)
77
     db = sqlite3.connect(dbpath)
73
     cursor1 = db.cursor()
78
     cursor1 = db.cursor()
74
     sqlstr11 = 'select PointName,Cal_X,Cal_Y,Last_CalX,Last_CalY,Last_CalP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
79
     sqlstr11 = 'select PointName,Cal_X,Cal_Y,Last_CalX,Last_CalY,Last_CalP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
75
-    cursor1.execute(sqlstr11,(utf_en,))
76
-    #获取结果集
80
+    cursor1.execute(sqlstr11, (utf_en,))
81
+    # 获取结果集
77
     result1 = cursor1.fetchall()
82
     result1 = cursor1.fetchall()
78
-    #整理数据
83
+    # 整理数据
79
     plist1 = Arrange_Data1(result1)
84
     plist1 = Arrange_Data1(result1)
80
     ws1.column_dimensions['A'].width = 5
85
     ws1.column_dimensions['A'].width = 5
81
     ws1.column_dimensions['B'].width = 15
86
     ws1.column_dimensions['B'].width = 15
97
                     start_column=4, end_column=6)
102
                     start_column=4, end_column=6)
98
     ws1.cell(2, 4).value = plist1[0][7] + '-归算成果(mm)'
103
     ws1.cell(2, 4).value = plist1[0][7] + '-归算成果(mm)'
99
     ws_area = ws1["A1:H3"]
104
     ws_area = ws1["A1:H3"]
100
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
105
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
101
     for i in ws_area:
106
     for i in ws_area:
102
         for j in i:
107
         for j in i:
103
             j.alignment = alignment_center
108
             j.alignment = alignment_center
104
     alignment_right = Alignment(horizontal='right', vertical='center')
109
     alignment_right = Alignment(horizontal='right', vertical='center')
105
     ws1.merge_cells(start_row=2, end_row=3,
110
     ws1.merge_cells(start_row=2, end_row=3,
106
-        start_column=7, end_column=7)
111
+                    start_column=7, end_column=7)
107
     ws1.cell(2, 7).value = '位移判定'
112
     ws1.cell(2, 7).value = '位移判定'
108
     ws1.cell(2, 7).alignment = Alignment(wrap_text=True)
113
     ws1.cell(2, 7).alignment = Alignment(wrap_text=True)
109
     ws1.cell(3, 2).value = 'X(mm)'
114
     ws1.cell(3, 2).value = 'X(mm)'
113
     ws1.cell(3, 6).value = '△P'
118
     ws1.cell(3, 6).value = '△P'
114
     row1 = 4
119
     row1 = 4
115
     for data1 in plist1:
120
     for data1 in plist1:
116
-        ws1.cell(row1,1).value = data1[0]
117
-        ws1.cell(row1,2).value = round(data1[1],4)
118
-        ws1.cell(row1,3).value = round(data1[2],4)
119
-        ws1.cell(row1,4).value = round(data1[3],1)
120
-        ws1.cell(row1,5).value = round(data1[4],1)
121
-        ws1.cell(row1,6).value = round(data1[5],1)
121
+        ws1.cell(row1, 1).value = data1[0]
122
+        ws1.cell(row1, 2).value = round(data1[1], 4)
123
+        ws1.cell(row1, 3).value = round(data1[2], 4)
124
+        ws1.cell(row1, 4).value = round(data1[3], 1)
125
+        ws1.cell(row1, 5).value = round(data1[4], 1)
126
+        ws1.cell(row1, 6).value = round(data1[5], 1)
122
         if data1[6] == '稳定':
127
         if data1[6] == '稳定':
123
-            ws1.cell(row1,7).value = ''
128
+            ws1.cell(row1, 7).value = ''
124
         else:
129
         else:
125
-            ws1.cell(row1,7).value = data1[6]
130
+            ws1.cell(row1, 7).value = data1[6]
126
         row1 = row1 + 1
131
         row1 = row1 + 1
127
 
132
 
128
-    #ws2部分(复测成果表)
129
-    #提取数据
133
+    # ws2部分(复测成果表)
134
+    # 提取数据
130
     sqlstr1 = 'select PointName,Last_X,Last_Y,Result_X,Result_Y,Last_ResultX,Last_ResultY,Last_ResultP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
135
     sqlstr1 = 'select PointName,Last_X,Last_Y,Result_X,Result_Y,Last_ResultX,Last_ResultY,Last_ResultP,Dis_Ass,Last_ResultName,New_ResultName from GS_Result_Point WHERE TableName = ?'
131
-    cursor1.execute(sqlstr1,(utf_en,))
132
-    #获取结果集
136
+    cursor1.execute(sqlstr1, (utf_en,))
137
+    # 获取结果集
133
     result2 = cursor1.fetchall()
138
     result2 = cursor1.fetchall()
134
-    #整理数据
139
+    # 整理数据
135
     plist2 = Arrange_Data2(result2)
140
     plist2 = Arrange_Data2(result2)
136
     ws2.column_dimensions['A'].width = 5
141
     ws2.column_dimensions['A'].width = 5
137
     ws2.column_dimensions['B'].width = 15
142
     ws2.column_dimensions['B'].width = 15
149
                     start_column=4, end_column=9)
154
                     start_column=4, end_column=9)
150
     ws2.cell(1, 4).value = '本期成果'
155
     ws2.cell(1, 4).value = '本期成果'
151
     ws_area = ws2["A1:I2"]
156
     ws_area = ws2["A1:I2"]
152
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
157
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
153
     for i in ws_area:
158
     for i in ws_area:
154
         for j in i:
159
         for j in i:
155
             j.alignment = alignment_center
160
             j.alignment = alignment_center
180
     ws2.cell(3, 8).value = '△XY'
185
     ws2.cell(3, 8).value = '△XY'
181
     row2 = 4
186
     row2 = 4
182
     for data2 in plist2:
187
     for data2 in plist2:
183
-        ws2.cell(row2,1).value = data2[0]
184
-        ws2.cell(row2,2).value = round(data2[1],4)
185
-        ws2.cell(row2,3).value = round(data2[2],4)
186
-        ws2.cell(row2,4).value = round(data2[3],4)
187
-        ws2.cell(row2,5).value = round(data2[4],4)
188
-        ws2.cell(row2,6).value = round(data2[5],1)
189
-        ws2.cell(row2,7).value = round(data2[6],1)
190
-        ws2.cell(row2,8).value = round(data2[7],1)
188
+        ws2.cell(row2, 1).value = data2[0]
189
+        ws2.cell(row2, 2).value = round(data2[1], 4)
190
+        ws2.cell(row2, 3).value = round(data2[2], 4)
191
+        ws2.cell(row2, 4).value = round(data2[3], 4)
192
+        ws2.cell(row2, 5).value = round(data2[4], 4)
193
+        ws2.cell(row2, 6).value = round(data2[5], 1)
194
+        ws2.cell(row2, 7).value = round(data2[6], 1)
195
+        ws2.cell(row2, 8).value = round(data2[7], 1)
191
         if data2[8] == '稳定':
196
         if data2[8] == '稳定':
192
-            ws2.cell(row2,9).value = ''
197
+            ws2.cell(row2, 9).value = ''
193
         else:
198
         else:
194
-            ws2.cell(row2,9).value = data2[8]
199
+            ws2.cell(row2, 9).value = data2[8]
195
         row2 = row2 + 1
200
         row2 = row2 + 1
196
-    
197
-    #ws3部分(公式)
198
-    #提取数据
201
+
202
+    # ws3部分(公式)
203
+    # 提取数据
199
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from GS_Trans_Param WHERE TableName = ?'
204
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from GS_Trans_Param WHERE TableName = ?'
200
-    cursor1.execute(sqlstr2,(utf_en,))
201
-    #获取结果集
202
-    result3 = cursor1.fetchall() 
205
+    cursor1.execute(sqlstr2, (utf_en,))
206
+    # 获取结果集
207
+    result3 = cursor1.fetchall()
203
     newname = result3[0][1].decode('utf-8')
208
     newname = result3[0][1].decode('utf-8')
204
     lastname = result3[0][0].decode('utf-8')
209
     lastname = result3[0][0].decode('utf-8')
205
     ws3.column_dimensions['A'].width = 75
210
     ws3.column_dimensions['A'].width = 75
206
     ws_area = ws3["A1:A5"]
211
     ws_area = ws3["A1:A5"]
207
-    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
212
+    alignment_center = Alignment(horizontal='left', vertical='center')  # 指定区域单元格居中
208
     for i in ws_area:
213
     for i in ws_area:
209
         for j in i:
214
         for j in i:
210
             j.alignment = alignment_center
215
             j.alignment = alignment_center
211
     str1 = newname + '--' + lastname + '已知系统转换公式:'
216
     str1 = newname + '--' + lastname + '已知系统转换公式:'
212
     ws3.cell(1, 1).value = str1
217
     ws3.cell(1, 1).value = str1
213
-    str2 = 'X=(' + str(round(result3[0][2],14)) + ')·x+(' + str(round(result3[0][3],14)) + ')·y+(' + str(round(result3[0][4],11)) + ')'
218
+    str2 = 'X=(' + str(round(result3[0][2], 14)) + ')·x+(' + str(round(result3[0][3], 14)) + ')·y+(' + str(
219
+        round(result3[0][4], 11)) + ')'
214
     ws3.cell(2, 1).value = str2
220
     ws3.cell(2, 1).value = str2
215
-    str3 = 'Y=(' + str(round(result3[0][5],14)) + ')·x+(' + str(round(result3[0][6],14)) + ')·y+(' + str(round(result3[0][7],11)) + ')'
221
+    str3 = 'Y=(' + str(round(result3[0][5], 14)) + ')·x+(' + str(round(result3[0][6], 14)) + ')·y+(' + str(
222
+        round(result3[0][7], 11)) + ')'
216
     ws3.cell(3, 1).value = str3
223
     ws3.cell(3, 1).value = str3
217
     str4 = '式中:x、y为' + newname
224
     str4 = '式中:x、y为' + newname
218
     ws3.cell(4, 1).value = str4
225
     ws3.cell(4, 1).value = str4
219
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
226
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
220
     ws3.cell(5, 1).value = str5
227
     ws3.cell(5, 1).value = str5
221
-    #保存
222
-    wb.save(outpath)
223
-    
228
+    # 保存
229
+    # wb.save(outpath)
230
+    # 保存 Excel 文件
231
+    excel_filename = f"控制网复测平面基准计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
232
+    excel_filepath = os.path.join(file_name, excel_filename)
233
+    wb.save(excel_filepath)
234
+
224
 
235
 
225
 # 主函数 写入excel文件
236
 # 主函数 写入excel文件
226
-def main_function(outpath,dbpath,file_path):
227
-    dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
228
-    outpath = r'D:\4work_now\20240819GS\JPG\GS成果表.xlsx'
229
-    file_path = r'D:\4work_now\20240819GS\二滩_20240816.xls'
230
-    file_name = os.path.basename(file_path)
231
-    # outpath为包含输出excel名字的全路径
232
-    openpyxl_write(outpath,dbpath,file_name)
233
-# dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
234
-# outpath = r'D:\4work_now\20240819GS\JPG\GS成果表.xlsx'
235
-# file_path = r'D:\4work_now\20240819GS\二滩_20240816.xls'
236
-# file_name = os.path.basename(file_path)
237
-# # outpath为包含输出excel名字的全路径
238
-# openpyxl_write(outpath,dbpath,file_name)
237
+def main_function(ui, file_path, dbpath, excelname):
238
+    # dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
239
+    # outpath = r'D:\4work_now\20240819GS\JPG\GS成果表.xlsx'
240
+    # file_path = r'D:\4work_now\20240819GS\二滩_20240816.xls'
241
+    file_name = os.path.dirname(file_path)
242
+    try:
243
+        openpyxl_write(file_name, dbpath, excelname)
244
+        QMessageBox.information(ui, '成功', f'成果文件已成功导出到 {file_name}')
245
+    except Exception as e:
246
+        QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
247
+

+ 64
- 54
Back/WD/WDExport.py Переглянути файл

1
 import openpyxl
1
 import openpyxl
2
 import sqlite3
2
 import sqlite3
3
 import os
3
 import os
4
+import time
4
 from openpyxl.styles import Alignment
5
 from openpyxl.styles import Alignment
6
+from PySide6.QtWidgets import QMessageBox
7
+
5
 
8
 
6
 def Arrange_Data1(list1):
9
 def Arrange_Data1(list1):
7
-    #最终return的
10
+    # 最终return的
8
     list2 = []
11
     list2 = []
9
     for data1 in list1:
12
     for data1 in list1:
10
-        #点名
11
-        #存每一行的数据
13
+        # 点名
14
+        # 存每一行的数据
12
         resultlist = []
15
         resultlist = []
13
         pn = data1[0].decode('utf-8')
16
         pn = data1[0].decode('utf-8')
14
         resultlist.append(pn)
17
         resultlist.append(pn)
23
         resultlist.append(data1[9])
26
         resultlist.append(data1[9])
24
         resultlist.append(data1[10])
27
         resultlist.append(data1[10])
25
         resultlist.append(data1[11])
28
         resultlist.append(data1[11])
26
-        #判定1
29
+        # 判定1
27
         an1 = data1[12].decode('utf-8')
30
         an1 = data1[12].decode('utf-8')
28
         resultlist.append(an1)
31
         resultlist.append(an1)
29
         resultlist.append(data1[13])
32
         resultlist.append(data1[13])
30
         resultlist.append(data1[14])
33
         resultlist.append(data1[14])
31
         resultlist.append(data1[15])
34
         resultlist.append(data1[15])
32
-        #判定2
35
+        # 判定2
33
         an2 = data1[16].decode('utf-8')
36
         an2 = data1[16].decode('utf-8')
34
         resultlist.append(an2)
37
         resultlist.append(an2)
35
-        #3个名字(首,上,新)
38
+        # 3个名字(首,上,新)
36
         name1 = data1[17].decode('utf-8')
39
         name1 = data1[17].decode('utf-8')
37
         resultlist.append(name1)
40
         resultlist.append(name1)
38
         name2 = data1[18].decode('utf-8')
41
         name2 = data1[18].decode('utf-8')
40
         name3 = data1[19].decode('utf-8')
43
         name3 = data1[19].decode('utf-8')
41
         resultlist.append(name3)
44
         resultlist.append(name3)
42
         list2.append(resultlist)
45
         list2.append(resultlist)
43
-    
46
+
44
     return list2
47
     return list2
45
 
48
 
46
-def openpyxl_write(outpath,dbpath,filename):
49
+
50
+def openpyxl_write(file_name, dbpath, filename):
47
     utf_en = filename.encode('utf-8')
51
     utf_en = filename.encode('utf-8')
48
-    #新建对应的excel
52
+    # 新建对应的excel
49
     wb = openpyxl.Workbook()
53
     wb = openpyxl.Workbook()
50
     ws1 = wb.create_sheet('稳定性分析成果表')
54
     ws1 = wb.create_sheet('稳定性分析成果表')
51
     ws2 = wb.create_sheet('改算模型')
55
     ws2 = wb.create_sheet('改算模型')
52
     ws3 = wb['Sheet']
56
     ws3 = wb['Sheet']
53
     wb.remove(ws3)
57
     wb.remove(ws3)
54
 
58
 
55
-    #ws1部分(成果表)
56
-    #提取数据
59
+    # ws1部分(成果表)
60
+    # 提取数据
57
     db1 = sqlite3.connect(dbpath)
61
     db1 = sqlite3.connect(dbpath)
58
-    #获取游标
62
+    # 获取游标
59
     cursor1 = db1.cursor()
63
     cursor1 = db1.cursor()
60
     sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,First_ResultName,Last_ResultName,New_ResultName from WD_Result_Point WHERE TableName = ?'
64
     sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,First_ResultName,Last_ResultName,New_ResultName from WD_Result_Point WHERE TableName = ?'
61
-    cursor1.execute(sqlstr1,(utf_en,))
62
-    #获取结果集
65
+    cursor1.execute(sqlstr1, (utf_en,))
66
+    # 获取结果集
63
     result1 = cursor1.fetchall()
67
     result1 = cursor1.fetchall()
64
-    #整理数据
68
+    # 整理数据
65
     plist1 = Arrange_Data1(result1)
69
     plist1 = Arrange_Data1(result1)
66
     ws1.column_dimensions['B'].width = 15
70
     ws1.column_dimensions['B'].width = 15
67
     ws1.column_dimensions['C'].width = 15
71
     ws1.column_dimensions['C'].width = 15
83
                     start_column=1, end_column=17)
87
                     start_column=1, end_column=17)
84
     ws1.cell(1, 1).value = '稳定性分析成果表'
88
     ws1.cell(1, 1).value = '稳定性分析成果表'
85
     ws_area = ws1["A1:Q2"]
89
     ws_area = ws1["A1:Q2"]
86
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
90
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
87
     for i in ws_area:
91
     for i in ws_area:
88
         for j in i:
92
         for j in i:
89
             j.alignment = alignment_center
93
             j.alignment = alignment_center
132
 
136
 
133
     row1 = 4
137
     row1 = 4
134
     for data1 in plist1:
138
     for data1 in plist1:
135
-        ws1.cell(row1,1).value = data1[0]
136
-        ws1.cell(row1,2).value = round(data1[1],4)
137
-        ws1.cell(row1,3).value = round(data1[2],4)
138
-        ws1.cell(row1,4).value = round(data1[3],4)
139
-        ws1.cell(row1,5).value = round(data1[4],4)
140
-        ws1.cell(row1,6).value = int(data1[5])
141
-        ws1.cell(row1,7).value = round(data1[6],4)
142
-        ws1.cell(row1,8).value = round(data1[7],4)
143
-        ws1.cell(row1,9).value = int(data1[8])
144
-        ws1.cell(row1,10).value = round(data1[9],1)
145
-        ws1.cell(row1,11).value = round(data1[10],1)
146
-        ws1.cell(row1,12).value = round(data1[11],1)
139
+        ws1.cell(row1, 1).value = data1[0]
140
+        ws1.cell(row1, 2).value = round(data1[1], 4)
141
+        ws1.cell(row1, 3).value = round(data1[2], 4)
142
+        ws1.cell(row1, 4).value = round(data1[3], 4)
143
+        ws1.cell(row1, 5).value = round(data1[4], 4)
144
+        ws1.cell(row1, 6).value = int(data1[5])
145
+        ws1.cell(row1, 7).value = round(data1[6], 4)
146
+        ws1.cell(row1, 8).value = round(data1[7], 4)
147
+        ws1.cell(row1, 9).value = int(data1[8])
148
+        ws1.cell(row1, 10).value = round(data1[9], 1)
149
+        ws1.cell(row1, 11).value = round(data1[10], 1)
150
+        ws1.cell(row1, 12).value = round(data1[11], 1)
147
         if data1[12] == '稳定':
151
         if data1[12] == '稳定':
148
-            ws1.cell(row1,13).value = ''
152
+            ws1.cell(row1, 13).value = ''
149
         else:
153
         else:
150
-            ws1.cell(row1,13).value = data1[12]
151
-        ws1.cell(row1,14).value = round(data1[13],1)
152
-        ws1.cell(row1,15).value = round(data1[14],1)
153
-        ws1.cell(row1,16).value = round(data1[15],1)
154
+            ws1.cell(row1, 13).value = data1[12]
155
+        ws1.cell(row1, 14).value = round(data1[13], 1)
156
+        ws1.cell(row1, 15).value = round(data1[14], 1)
157
+        ws1.cell(row1, 16).value = round(data1[15], 1)
154
         if data1[16] == '稳定':
158
         if data1[16] == '稳定':
155
-            ws1.cell(row1,17).value = ''
159
+            ws1.cell(row1, 17).value = ''
156
         else:
160
         else:
157
-            ws1.cell(row1,17).value = data1[16]
161
+            ws1.cell(row1, 17).value = data1[16]
158
         row1 = row1 + 1
162
         row1 = row1 + 1
159
 
163
 
160
-    #ws2部分(公式)
161
-    #提取数据
164
+    # ws2部分(公式)
165
+    # 提取数据
162
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
166
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
163
-    cursor1.execute(sqlstr2,(utf_en,))
164
-    #获取结果集
165
-    result3 = cursor1.fetchall() 
167
+    cursor1.execute(sqlstr2, (utf_en,))
168
+    # 获取结果集
169
+    result3 = cursor1.fetchall()
166
     newname = result3[0][1].decode('utf-8')
170
     newname = result3[0][1].decode('utf-8')
167
     lastname = result3[0][0].decode('utf-8')
171
     lastname = result3[0][0].decode('utf-8')
168
     ws2.column_dimensions['A'].width = 75
172
     ws2.column_dimensions['A'].width = 75
169
     ws_area = ws2["A1:A5"]
173
     ws_area = ws2["A1:A5"]
170
-    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
174
+    alignment_center = Alignment(horizontal='left', vertical='center')  # 指定区域单元格居中
171
     for i in ws_area:
175
     for i in ws_area:
172
         for j in i:
176
         for j in i:
173
             j.alignment = alignment_center
177
             j.alignment = alignment_center
174
     str1 = newname + '--' + lastname + '已知系统转换公式:'
178
     str1 = newname + '--' + lastname + '已知系统转换公式:'
175
     ws2.cell(1, 1).value = str1
179
     ws2.cell(1, 1).value = str1
176
-    str2 = 'X=(' + str(round(result3[0][2],14)) + ')·x+(' + str(round(result3[0][3],14)) + ')·y+(' + str(round(result3[0][4],11)) + ')'
180
+    str2 = 'X=(' + str(round(result3[0][2], 14)) + ')·x+(' + str(round(result3[0][3], 14)) + ')·y+(' + str(
181
+        round(result3[0][4], 11)) + ')'
177
     ws2.cell(2, 1).value = str2
182
     ws2.cell(2, 1).value = str2
178
-    str3 = 'Y=(' + str(round(result3[0][5],14)) + ')·x+(' + str(round(result3[0][6],14)) + ')·y+(' + str(round(result3[0][7],11)) + ')'
183
+    str3 = 'Y=(' + str(round(result3[0][5], 14)) + ')·x+(' + str(round(result3[0][6], 14)) + ')·y+(' + str(
184
+        round(result3[0][7], 11)) + ')'
179
     ws2.cell(3, 1).value = str3
185
     ws2.cell(3, 1).value = str3
180
     str4 = '式中:x、y为' + newname
186
     str4 = '式中:x、y为' + newname
181
     ws2.cell(4, 1).value = str4
187
     ws2.cell(4, 1).value = str4
182
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
188
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
183
     ws2.cell(5, 1).value = str5
189
     ws2.cell(5, 1).value = str5
184
-    #保存
185
-    wb.save(outpath)
190
+    # 保存 Excel 文件
191
+    excel_filename = f"平面控制网稳定性计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
192
+    excel_filepath = os.path.join(file_name, excel_filename)
193
+    wb.save(excel_filepath)
186
 
194
 
187
 
195
 
188
 # 主函数 写入excel文件
196
 # 主函数 写入excel文件
189
-def main_function(outpath,dbpath,file_path):
190
-    dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
191
-    outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
192
-    file_path = r'D:\4work_now\20240819GS\test_wd.xls'
193
-    file_name = os.path.basename(file_path)
194
-    # outpath为包含输出excel名字的全路径
195
-    openpyxl_write(outpath,dbpath,file_name)
196
-
197
+def main_function(ui, file_path, dbpath, excelname):
198
+    # dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
199
+    # outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
200
+    # file_path = r'D:\4work_now\20240819GS\test_wd.xls'
201
+    file_name = os.path.dirname(file_path)
202
+    try:
203
+        openpyxl_write(file_name, dbpath, excelname)
204
+        QMessageBox.information(ui, '成功', f'成果文件已成功导出到 {file_name}')
205
+    except Exception as e:
206
+        QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
197
 
207
 
198
 # dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
208
 # dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
199
 # # dbpath = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
209
 # # dbpath = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
201
 # file_path = r'D:\4work_now\20240819GS\test_wd.xls'
211
 # file_path = r'D:\4work_now\20240819GS\test_wd.xls'
202
 # file_name = os.path.basename(file_path)
212
 # file_name = os.path.basename(file_path)
203
 # # outpath为包含输出excel名字的全路径
213
 # # outpath为包含输出excel名字的全路径
204
-# openpyxl_write(outpath,dbpath,file_name)
214
+# openpyxl_write(outpath,dbpath,file_name)

+ 5
- 6
Front/modules/ui_functions.py Переглянути файл

356
         if current_text == "水准测段高差稳定计算":
356
         if current_text == "水准测段高差稳定计算":
357
             GCExport.main_function(self, file_path, utf_en, db_path)
357
             GCExport.main_function(self, file_path, utf_en, db_path)
358
         elif current_text == "控制网复测平面基准计算":
358
         elif current_text == "控制网复测平面基准计算":
359
-            GSExport.main_function(self, db_path, file_path)
359
+            GSExport.main_function(self, file_path, db_path, excelname)
360
         elif current_text == "平面控制网稳定性计算":
360
         elif current_text == "平面控制网稳定性计算":
361
-            # WDExport.main_function(self, file_path)
362
-            pass
361
+            WDExport.main_function(self, file_path, db_path, excelname)
363
         else:
362
         else:
364
             QMessageBox.warning(self, '警告', '请选择有效的计算类型')
363
             QMessageBox.warning(self, '警告', '请选择有效的计算类型')
365
 
364
 
366
-    #数据一览,点击查询
367
-    def search_data_to_show(self,file_path,current_text,tablename):
365
+    # 数据一览,点击查询
366
+    def search_data_to_show(self, file_path, current_text, tablename):
368
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
367
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
369
-        #高差部分我没改
368
+        # 高差部分我没改
370
         if current_text == "水准测段高差稳定计算":
369
         if current_text == "水准测段高差稳定计算":
371
             GCshow.main_function(self.ui, file_path, utf_en)
370
             GCshow.main_function(self.ui, file_path, utf_en)
372
         elif current_text == "控制网复测平面基准计算":
371
         elif current_text == "控制网复测平面基准计算":


Завантаження…
Відмінити
Зберегти