|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+import openpyxl
|
|
|
2
|
+import sqlite3
|
|
|
3
|
+import os
|
|
|
4
|
+from openpyxl.styles import Alignment
|
|
|
5
|
+
|
|
|
6
|
+def Arrange_Data1(list1):
|
|
|
7
|
+ #最终return的
|
|
|
8
|
+ list2 = []
|
|
|
9
|
+ for data1 in list1:
|
|
|
10
|
+ #点名
|
|
|
11
|
+ #存每一行的数据
|
|
|
12
|
+ resultlist = []
|
|
|
13
|
+ pn = data1[0].decode('utf-8')
|
|
|
14
|
+ resultlist.append(pn)
|
|
|
15
|
+ resultlist.append(data1[1])
|
|
|
16
|
+ resultlist.append(data1[2])
|
|
|
17
|
+ resultlist.append(data1[3])
|
|
|
18
|
+ resultlist.append(data1[4])
|
|
|
19
|
+ resultlist.append(data1[5])
|
|
|
20
|
+ #判定
|
|
|
21
|
+ an1 = data1[6].decode('utf-8')
|
|
|
22
|
+ resultlist.append(an1)
|
|
|
23
|
+ #两个结果名字(旧新)
|
|
|
24
|
+ name1 = data1[7].decode('utf-8')
|
|
|
25
|
+ resultlist.append(name1)
|
|
|
26
|
+ name2 = data1[8].decode('utf-8')
|
|
|
27
|
+ resultlist.append(name2)
|
|
|
28
|
+ list2.append(resultlist)
|
|
|
29
|
+ return list2
|
|
|
30
|
+
|
|
|
31
|
+#复测成果表
|
|
|
32
|
+def Arrange_Data2(list1):
|
|
|
33
|
+ #最终return的
|
|
|
34
|
+ list2 = []
|
|
|
35
|
+ for data1 in list1:
|
|
|
36
|
+ #点名
|
|
|
37
|
+ #存每一行的数据
|
|
|
38
|
+ resultlist = []
|
|
|
39
|
+ pn = data1[0].decode('utf-8')
|
|
|
40
|
+ resultlist.append(pn)
|
|
|
41
|
+ resultlist.append(data1[1])
|
|
|
42
|
+ resultlist.append(data1[2])
|
|
|
43
|
+ resultlist.append(data1[3])
|
|
|
44
|
+ resultlist.append(data1[4])
|
|
|
45
|
+ resultlist.append(data1[5])
|
|
|
46
|
+ resultlist.append(data1[6])
|
|
|
47
|
+ resultlist.append(data1[7])
|
|
|
48
|
+ #判定
|
|
|
49
|
+ an1 = data1[8].decode('utf-8')
|
|
|
50
|
+ resultlist.append(an1)
|
|
|
51
|
+ #两个结果名字(旧新)
|
|
|
52
|
+ name1 = data1[9].decode('utf-8')
|
|
|
53
|
+ resultlist.append(name1)
|
|
|
54
|
+ name2 = data1[10].decode('utf-8')
|
|
|
55
|
+ resultlist.append(name2)
|
|
|
56
|
+ list2.append(resultlist)
|
|
|
57
|
+
|
|
|
58
|
+ return list2
|
|
|
59
|
+
|
|
|
60
|
+def openpyxl_write(outpath,dbpath,filename):
|
|
|
61
|
+ utf_en = filename.encode('utf-8')
|
|
|
62
|
+ #新建对应的excel
|
|
|
63
|
+ wb = openpyxl.Workbook()
|
|
|
64
|
+ ws2 = wb.create_sheet('复测成果表')
|
|
|
65
|
+ ws1 = wb.create_sheet('复测基准归算表')
|
|
|
66
|
+ ws3 = wb.create_sheet('基准归算模型')
|
|
|
67
|
+ ws5 = wb['Sheet']
|
|
|
68
|
+ wb.remove(ws5)
|
|
|
69
|
+
|
|
|
70
|
+ #w1部分(基准归算表)
|
|
|
71
|
+ #提取数据
|
|
|
72
|
+ db = sqlite3.connect(dbpath)
|
|
|
73
|
+ 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 = ?'
|
|
|
75
|
+ cursor1.execute(sqlstr11,(utf_en,))
|
|
|
76
|
+ #获取结果集
|
|
|
77
|
+ result1 = cursor1.fetchall()
|
|
|
78
|
+ #整理数据
|
|
|
79
|
+ plist1 = Arrange_Data1(result1)
|
|
|
80
|
+ ws1.column_dimensions['A'].width = 5
|
|
|
81
|
+ ws1.column_dimensions['B'].width = 15
|
|
|
82
|
+ ws1.column_dimensions['C'].width = 15
|
|
|
83
|
+ ws1.column_dimensions['D'].width = 8
|
|
|
84
|
+ ws1.column_dimensions['E'].width = 8
|
|
|
85
|
+ ws1.column_dimensions['F'].width = 8
|
|
|
86
|
+ ws1.column_dimensions['G'].width = 5
|
|
|
87
|
+ ws1.merge_cells(start_row=1, end_row=1,
|
|
|
88
|
+ start_column=1, end_column=7)
|
|
|
89
|
+ ws1.cell(1, 1).value = '复测基准归算与位移判定'
|
|
|
90
|
+ ws1.merge_cells(start_row=2, end_row=3,
|
|
|
91
|
+ start_column=1, end_column=1)
|
|
|
92
|
+ ws1.cell(2, 1).value = '点名'
|
|
|
93
|
+ ws1.merge_cells(start_row=2, end_row=2,
|
|
|
94
|
+ start_column=2, end_column=3)
|
|
|
95
|
+ ws1.cell(2, 2).value = plist1[0][8] + '基准归算成果'
|
|
|
96
|
+ ws1.merge_cells(start_row=2, end_row=2,
|
|
|
97
|
+ start_column=4, end_column=6)
|
|
|
98
|
+ ws1.cell(2, 4).value = plist1[0][7] + '-归算成果(mm)'
|
|
|
99
|
+ ws_area = ws1["A1:H3"]
|
|
|
100
|
+ alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
|
|
|
101
|
+ for i in ws_area:
|
|
|
102
|
+ for j in i:
|
|
|
103
|
+ j.alignment = alignment_center
|
|
|
104
|
+ alignment_right = Alignment(horizontal='right', vertical='center')
|
|
|
105
|
+ ws1.merge_cells(start_row=2, end_row=3,
|
|
|
106
|
+ start_column=7, end_column=7)
|
|
|
107
|
+ ws1.cell(2, 7).value = '位移判定'
|
|
|
108
|
+ ws1.cell(2, 7).alignment = Alignment(wrap_text=True)
|
|
|
109
|
+ ws1.cell(3, 2).value = 'X(mm)'
|
|
|
110
|
+ ws1.cell(3, 3).value = 'Y(mm)'
|
|
|
111
|
+ ws1.cell(3, 4).value = '△X'
|
|
|
112
|
+ ws1.cell(3, 5).value = '△Y'
|
|
|
113
|
+ ws1.cell(3, 6).value = '△P'
|
|
|
114
|
+ row1 = 4
|
|
|
115
|
+ 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)
|
|
|
122
|
+ if data1[6] == '稳定':
|
|
|
123
|
+ ws1.cell(row1,7).value = ''
|
|
|
124
|
+ else:
|
|
|
125
|
+ ws1.cell(row1,7).value = data1[6]
|
|
|
126
|
+ row1 = row1 + 1
|
|
|
127
|
+
|
|
|
128
|
+ #ws2部分(复测成果表)
|
|
|
129
|
+ #提取数据
|
|
|
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 = ?'
|
|
|
131
|
+ cursor1.execute(sqlstr1,(utf_en,))
|
|
|
132
|
+ #获取结果集
|
|
|
133
|
+ result2 = cursor1.fetchall()
|
|
|
134
|
+ #整理数据
|
|
|
135
|
+ plist2 = Arrange_Data2(result2)
|
|
|
136
|
+ ws2.column_dimensions['A'].width = 5
|
|
|
137
|
+ ws2.column_dimensions['B'].width = 15
|
|
|
138
|
+ ws2.column_dimensions['C'].width = 15
|
|
|
139
|
+ ws2.column_dimensions['D'].width = 15
|
|
|
140
|
+ ws2.column_dimensions['E'].width = 15
|
|
|
141
|
+ ws2.column_dimensions['F'].width = 8
|
|
|
142
|
+ ws2.column_dimensions['G'].width = 8
|
|
|
143
|
+ ws2.column_dimensions['H'].width = 8
|
|
|
144
|
+ ws2.column_dimensions['I'].width = 5
|
|
|
145
|
+ ws2.merge_cells(start_row=1, end_row=1,
|
|
|
146
|
+ start_column=1, end_column=3)
|
|
|
147
|
+ ws2.cell(1, 1).value = '前期成果'
|
|
|
148
|
+ ws2.merge_cells(start_row=1, end_row=1,
|
|
|
149
|
+ start_column=4, end_column=9)
|
|
|
150
|
+ ws2.cell(1, 4).value = '本期成果'
|
|
|
151
|
+ ws_area = ws2["A1:I2"]
|
|
|
152
|
+ alignment_center = Alignment(horizontal='center', vertical='center')# 指定区域单元格居中
|
|
|
153
|
+ for i in ws_area:
|
|
|
154
|
+ for j in i:
|
|
|
155
|
+ j.alignment = alignment_center
|
|
|
156
|
+ alignment_right = Alignment(horizontal='right', vertical='center')
|
|
|
157
|
+ ws2.merge_cells(start_row=2, end_row=3,
|
|
|
158
|
+ start_column=1, end_column=1)
|
|
|
159
|
+ ws2.cell(2, 1).value = '点名'
|
|
|
160
|
+ ws2.merge_cells(start_row=2, end_row=2,
|
|
|
161
|
+ start_column=2, end_column=3)
|
|
|
162
|
+ ws2.cell(2, 2).value = plist2[0][9]
|
|
|
163
|
+ ws2.merge_cells(start_row=2, end_row=2,
|
|
|
164
|
+ start_column=4, end_column=5)
|
|
|
165
|
+ ws2.cell(2, 4).value = plist2[0][10]
|
|
|
166
|
+ ws2.merge_cells(start_row=2, end_row=2,
|
|
|
167
|
+ start_column=6, end_column=8)
|
|
|
168
|
+ newname_1 = plist2[0][9] + '-' + plist2[0][10] + '(mm)'
|
|
|
169
|
+ ws2.cell(2, 6).value = newname_1
|
|
|
170
|
+ ws2.merge_cells(start_row=2, end_row=3,
|
|
|
171
|
+ start_column=9, end_column=9)
|
|
|
172
|
+ ws2.cell(2, 9).value = '位移判定'
|
|
|
173
|
+ ws2.cell(2, 9).alignment = Alignment(wrap_text=True)
|
|
|
174
|
+ ws2.cell(3, 2).value = 'X(m)'
|
|
|
175
|
+ ws2.cell(3, 3).value = 'Y(m)'
|
|
|
176
|
+ ws2.cell(3, 4).value = 'X(m)'
|
|
|
177
|
+ ws2.cell(3, 5).value = 'Y(m)'
|
|
|
178
|
+ ws2.cell(3, 6).value = '△X'
|
|
|
179
|
+ ws2.cell(3, 7).value = '△Y'
|
|
|
180
|
+ ws2.cell(3, 8).value = '△XY'
|
|
|
181
|
+ row2 = 4
|
|
|
182
|
+ 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)
|
|
|
191
|
+ if data2[8] == '稳定':
|
|
|
192
|
+ ws2.cell(row2,9).value = ''
|
|
|
193
|
+ else:
|
|
|
194
|
+ ws2.cell(row2,9).value = data2[8]
|
|
|
195
|
+ row2 = row2 + 1
|
|
|
196
|
+
|
|
|
197
|
+ #ws3部分(公式)
|
|
|
198
|
+ #提取数据
|
|
|
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 = ?'
|
|
|
200
|
+ cursor1.execute(sqlstr2,(utf_en,))
|
|
|
201
|
+ #获取结果集
|
|
|
202
|
+ result3 = cursor1.fetchall()
|
|
|
203
|
+ newname = result3[0][1].decode('utf-8')
|
|
|
204
|
+ lastname = result3[0][0].decode('utf-8')
|
|
|
205
|
+ ws3.column_dimensions['A'].width = 75
|
|
|
206
|
+ ws_area = ws3["A1:A5"]
|
|
|
207
|
+ alignment_center = Alignment(horizontal='left', vertical='center')# 指定区域单元格居中
|
|
|
208
|
+ for i in ws_area:
|
|
|
209
|
+ for j in i:
|
|
|
210
|
+ j.alignment = alignment_center
|
|
|
211
|
+ str1 = newname + '--' + lastname + '已知系统转换公式:'
|
|
|
212
|
+ 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)) + ')'
|
|
|
214
|
+ 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)) + ')'
|
|
|
216
|
+ ws3.cell(3, 1).value = str3
|
|
|
217
|
+ str4 = '式中:x、y为' + newname
|
|
|
218
|
+ ws3.cell(4, 1).value = str4
|
|
|
219
|
+ str5 = ' X、Y为' + lastname + '已知系统的' + newname + '归算坐标'
|
|
|
220
|
+ ws3.cell(5, 1).value = str5
|
|
|
221
|
+ #保存
|
|
|
222
|
+ wb.save(outpath)
|
|
|
223
|
+
|
|
|
224
|
+
|
|
|
225
|
+# 主函数 写入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)
|