|
@@ -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
|
+
|