浏览代码

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

wzp 5 个月前
父节点
当前提交
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. 二进制
      SQL/1.db

+ 3
- 1
.gitignore 查看文件

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

+ 7
- 3
Back/GC/GCExport.py 查看文件

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

+ 79
- 70
Back/GS/GSExport.py 查看文件

@@ -1,14 +1,17 @@
1 1
 import openpyxl
2 2
 import sqlite3
3 3
 import os
4
+import time
4 5
 from openpyxl.styles import Alignment
6
+from PySide6.QtWidgets import QMessageBox
7
+
5 8
 
6 9
 def Arrange_Data1(list1):
7
-    #最终return的
10
+    # 最终return的
8 11
     list2 = []
9 12
     for data1 in list1:
10
-        #点名
11
-        #存每一行的数据
13
+        # 点名
14
+        # 存每一行的数据
12 15
         resultlist = []
13 16
         pn = data1[0].decode('utf-8')
14 17
         resultlist.append(pn)
@@ -17,10 +20,10 @@ def Arrange_Data1(list1):
17 20
         resultlist.append(data1[3])
18 21
         resultlist.append(data1[4])
19 22
         resultlist.append(data1[5])
20
-        #判定
23
+        # 判定
21 24
         an1 = data1[6].decode('utf-8')
22 25
         resultlist.append(an1)
23
-        #两个结果名字(旧新)
26
+        # 两个结果名字(旧新)
24 27
         name1 = data1[7].decode('utf-8')
25 28
         resultlist.append(name1)
26 29
         name2 = data1[8].decode('utf-8')
@@ -28,13 +31,14 @@ def Arrange_Data1(list1):
28 31
         list2.append(resultlist)
29 32
     return list2
30 33
 
31
-#复测成果表
34
+
35
+# 复测成果表
32 36
 def Arrange_Data2(list1):
33
-    #最终return的
37
+    # 最终return的
34 38
     list2 = []
35 39
     for data1 in list1:
36
-        #点名
37
-        #存每一行的数据
40
+        # 点名
41
+        # 存每一行的数据
38 42
         resultlist = []
39 43
         pn = data1[0].decode('utf-8')
40 44
         resultlist.append(pn)
@@ -45,21 +49,22 @@ def Arrange_Data2(list1):
45 49
         resultlist.append(data1[5])
46 50
         resultlist.append(data1[6])
47 51
         resultlist.append(data1[7])
48
-        #判定
52
+        # 判定
49 53
         an1 = data1[8].decode('utf-8')
50 54
         resultlist.append(an1)
51
-        #两个结果名字(旧新)
55
+        # 两个结果名字(旧新)
52 56
         name1 = data1[9].decode('utf-8')
53 57
         resultlist.append(name1)
54 58
         name2 = data1[10].decode('utf-8')
55 59
         resultlist.append(name2)
56 60
         list2.append(resultlist)
57
-    
61
+
58 62
     return list2
59 63
 
60
-def openpyxl_write(outpath,dbpath,filename):
64
+
65
+def openpyxl_write(file_name, dbpath, filename):
61 66
     utf_en = filename.encode('utf-8')
62
-    #新建对应的excel
67
+    # 新建对应的excel
63 68
     wb = openpyxl.Workbook()
64 69
     ws2 = wb.create_sheet('复测成果表')
65 70
     ws1 = wb.create_sheet('复测基准归算表')
@@ -67,15 +72,15 @@ def openpyxl_write(outpath,dbpath,filename):
67 72
     ws5 = wb['Sheet']
68 73
     wb.remove(ws5)
69 74
 
70
-    #w1部分(基准归算表)
71
-    #提取数据
75
+    # w1部分(基准归算表)
76
+    # 提取数据
72 77
     db = sqlite3.connect(dbpath)
73 78
     cursor1 = db.cursor()
74 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 82
     result1 = cursor1.fetchall()
78
-    #整理数据
83
+    # 整理数据
79 84
     plist1 = Arrange_Data1(result1)
80 85
     ws1.column_dimensions['A'].width = 5
81 86
     ws1.column_dimensions['B'].width = 15
@@ -97,13 +102,13 @@ def openpyxl_write(outpath,dbpath,filename):
97 102
                     start_column=4, end_column=6)
98 103
     ws1.cell(2, 4).value = plist1[0][7] + '-归算成果(mm)'
99 104
     ws_area = ws1["A1:H3"]
100
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
105
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
101 106
     for i in ws_area:
102 107
         for j in i:
103 108
             j.alignment = alignment_center
104 109
     alignment_right = Alignment(horizontal='right', vertical='center')
105 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 112
     ws1.cell(2, 7).value = '位移判定'
108 113
     ws1.cell(2, 7).alignment = Alignment(wrap_text=True)
109 114
     ws1.cell(3, 2).value = 'X(mm)'
@@ -113,25 +118,25 @@ def openpyxl_write(outpath,dbpath,filename):
113 118
     ws1.cell(3, 6).value = '△P'
114 119
     row1 = 4
115 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 127
         if data1[6] == '稳定':
123
-            ws1.cell(row1,7).value = ''
128
+            ws1.cell(row1, 7).value = ''
124 129
         else:
125
-            ws1.cell(row1,7).value = data1[6]
130
+            ws1.cell(row1, 7).value = data1[6]
126 131
         row1 = row1 + 1
127 132
 
128
-    #ws2部分(复测成果表)
129
-    #提取数据
133
+    # ws2部分(复测成果表)
134
+    # 提取数据
130 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 138
     result2 = cursor1.fetchall()
134
-    #整理数据
139
+    # 整理数据
135 140
     plist2 = Arrange_Data2(result2)
136 141
     ws2.column_dimensions['A'].width = 5
137 142
     ws2.column_dimensions['B'].width = 15
@@ -149,7 +154,7 @@ def openpyxl_write(outpath,dbpath,filename):
149 154
                     start_column=4, end_column=9)
150 155
     ws2.cell(1, 4).value = '本期成果'
151 156
     ws_area = ws2["A1:I2"]
152
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
157
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
153 158
     for i in ws_area:
154 159
         for j in i:
155 160
             j.alignment = alignment_center
@@ -180,59 +185,63 @@ def openpyxl_write(outpath,dbpath,filename):
180 185
     ws2.cell(3, 8).value = '△XY'
181 186
     row2 = 4
182 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 196
         if data2[8] == '稳定':
192
-            ws2.cell(row2,9).value = ''
197
+            ws2.cell(row2, 9).value = ''
193 198
         else:
194
-            ws2.cell(row2,9).value = data2[8]
199
+            ws2.cell(row2, 9).value = data2[8]
195 200
         row2 = row2 + 1
196
-    
197
-    #ws3部分(公式)
198
-    #提取数据
201
+
202
+    # ws3部分(公式)
203
+    # 提取数据
199 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 208
     newname = result3[0][1].decode('utf-8')
204 209
     lastname = result3[0][0].decode('utf-8')
205 210
     ws3.column_dimensions['A'].width = 75
206 211
     ws_area = ws3["A1:A5"]
207
-    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
212
+    alignment_center = Alignment(horizontal='left', vertical='center')  # 指定区域单元格居中
208 213
     for i in ws_area:
209 214
         for j in i:
210 215
             j.alignment = alignment_center
211 216
     str1 = newname + '--' + lastname + '已知系统转换公式:'
212 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 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 223
     ws3.cell(3, 1).value = str3
217 224
     str4 = '式中:x、y为' + newname
218 225
     ws3.cell(4, 1).value = str4
219 226
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
220 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 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,14 +1,17 @@
1 1
 import openpyxl
2 2
 import sqlite3
3 3
 import os
4
+import time
4 5
 from openpyxl.styles import Alignment
6
+from PySide6.QtWidgets import QMessageBox
7
+
5 8
 
6 9
 def Arrange_Data1(list1):
7
-    #最终return的
10
+    # 最终return的
8 11
     list2 = []
9 12
     for data1 in list1:
10
-        #点名
11
-        #存每一行的数据
13
+        # 点名
14
+        # 存每一行的数据
12 15
         resultlist = []
13 16
         pn = data1[0].decode('utf-8')
14 17
         resultlist.append(pn)
@@ -23,16 +26,16 @@ def Arrange_Data1(list1):
23 26
         resultlist.append(data1[9])
24 27
         resultlist.append(data1[10])
25 28
         resultlist.append(data1[11])
26
-        #判定1
29
+        # 判定1
27 30
         an1 = data1[12].decode('utf-8')
28 31
         resultlist.append(an1)
29 32
         resultlist.append(data1[13])
30 33
         resultlist.append(data1[14])
31 34
         resultlist.append(data1[15])
32
-        #判定2
35
+        # 判定2
33 36
         an2 = data1[16].decode('utf-8')
34 37
         resultlist.append(an2)
35
-        #3个名字(首,上,新)
38
+        # 3个名字(首,上,新)
36 39
         name1 = data1[17].decode('utf-8')
37 40
         resultlist.append(name1)
38 41
         name2 = data1[18].decode('utf-8')
@@ -40,28 +43,29 @@ def Arrange_Data1(list1):
40 43
         name3 = data1[19].decode('utf-8')
41 44
         resultlist.append(name3)
42 45
         list2.append(resultlist)
43
-    
46
+
44 47
     return list2
45 48
 
46
-def openpyxl_write(outpath,dbpath,filename):
49
+
50
+def openpyxl_write(file_name, dbpath, filename):
47 51
     utf_en = filename.encode('utf-8')
48
-    #新建对应的excel
52
+    # 新建对应的excel
49 53
     wb = openpyxl.Workbook()
50 54
     ws1 = wb.create_sheet('稳定性分析成果表')
51 55
     ws2 = wb.create_sheet('改算模型')
52 56
     ws3 = wb['Sheet']
53 57
     wb.remove(ws3)
54 58
 
55
-    #ws1部分(成果表)
56
-    #提取数据
59
+    # ws1部分(成果表)
60
+    # 提取数据
57 61
     db1 = sqlite3.connect(dbpath)
58
-    #获取游标
62
+    # 获取游标
59 63
     cursor1 = db1.cursor()
60 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 67
     result1 = cursor1.fetchall()
64
-    #整理数据
68
+    # 整理数据
65 69
     plist1 = Arrange_Data1(result1)
66 70
     ws1.column_dimensions['B'].width = 15
67 71
     ws1.column_dimensions['C'].width = 15
@@ -83,7 +87,7 @@ def openpyxl_write(outpath,dbpath,filename):
83 87
                     start_column=1, end_column=17)
84 88
     ws1.cell(1, 1).value = '稳定性分析成果表'
85 89
     ws_area = ws1["A1:Q2"]
86
-    alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
90
+    alignment_center = Alignment(horizontal='center', vertical='center')  # 指定区域单元格居中
87 91
     for i in ws_area:
88 92
         for j in i:
89 93
             j.alignment = alignment_center
@@ -132,68 +136,74 @@ def openpyxl_write(outpath,dbpath,filename):
132 136
 
133 137
     row1 = 4
134 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 151
         if data1[12] == '稳定':
148
-            ws1.cell(row1,13).value = ''
152
+            ws1.cell(row1, 13).value = ''
149 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 158
         if data1[16] == '稳定':
155
-            ws1.cell(row1,17).value = ''
159
+            ws1.cell(row1, 17).value = ''
156 160
         else:
157
-            ws1.cell(row1,17).value = data1[16]
161
+            ws1.cell(row1, 17).value = data1[16]
158 162
         row1 = row1 + 1
159 163
 
160
-    #ws2部分(公式)
161
-    #提取数据
164
+    # ws2部分(公式)
165
+    # 提取数据
162 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 170
     newname = result3[0][1].decode('utf-8')
167 171
     lastname = result3[0][0].decode('utf-8')
168 172
     ws2.column_dimensions['A'].width = 75
169 173
     ws_area = ws2["A1:A5"]
170
-    alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
174
+    alignment_center = Alignment(horizontal='left', vertical='center')  # 指定区域单元格居中
171 175
     for i in ws_area:
172 176
         for j in i:
173 177
             j.alignment = alignment_center
174 178
     str1 = newname + '--' + lastname + '已知系统转换公式:'
175 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 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 185
     ws2.cell(3, 1).value = str3
180 186
     str4 = '式中:x、y为' + newname
181 187
     ws2.cell(4, 1).value = str4
182 188
     str5 = '     X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
183 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 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 208
 # dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
199 209
 # # dbpath = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
@@ -201,4 +211,4 @@ def main_function(outpath,dbpath,file_path):
201 211
 # file_path = r'D:\4work_now\20240819GS\test_wd.xls'
202 212
 # file_name = os.path.basename(file_path)
203 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,17 +356,16 @@ class UIFunctions(MainWindow):
356 356
         if current_text == "水准测段高差稳定计算":
357 357
             GCExport.main_function(self, file_path, utf_en, db_path)
358 358
         elif current_text == "控制网复测平面基准计算":
359
-            GSExport.main_function(self, db_path, file_path)
359
+            GSExport.main_function(self, file_path, db_path, excelname)
360 360
         elif current_text == "平面控制网稳定性计算":
361
-            # WDExport.main_function(self, file_path)
362
-            pass
361
+            WDExport.main_function(self, file_path, db_path, excelname)
363 362
         else:
364 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 367
         utf_en = tablename.encode('utf-8')  # 转换文件名为utf-8编码形式
369
-        #高差部分我没改
368
+        # 高差部分我没改
370 369
         if current_text == "水准测段高差稳定计算":
371 370
             GCshow.main_function(self.ui, file_path, utf_en)
372 371
         elif current_text == "控制网复测平面基准计算":

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


正在加载...
取消
保存