forked from inmine2/FilesManagement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheachTable.py
254 lines (233 loc) · 10.7 KB
/
eachTable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Table.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtWidgets import QWidget, QCheckBox, QApplication, QPushButton, QMessageBox,QMainWindow,QInputDialog,QTextEdit,QFileDialog
from PyQt5.QtCore import Qt
import pandas as pd
from NoteBook import NoteBook
from File2 import ReadDoc
from openpyxl import load_workbook
import os
import re
class eachTable_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.retranslateUi(self)
def setupUi(self, Table):
Table.setObjectName("Table")
Table.resize(800, 800)
Table.setMinimumSize(QtCore.QSize(800, 800))
Table.setMaximumSize(QtCore.QSize(800, 800))
self.pathlabel = QtWidgets.QLabel()
self.pathlabel.setGeometry(QtCore.QRect(10, 10, 10, 100))
self.pathlabel.setText('')
self.pathlabel.setObjectName("label")
self.centralwidget = QtWidgets.QWidget(Table)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(280, 30, 228, 42))
self.label.setMaximumSize(QtCore.QSize(500, 1000))
self.label.setObjectName("label")
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(50, 70, 711, 16))
self.line.setLineWidth(2)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setEnabled(True)
self.scrollArea.setGeometry(QtCore.QRect(50, 80, 711, 611))
self.scrollArea.setLineWidth(1)
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -7, 709, 599))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.label_hetongxinxi = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_hetongxinxi.setGeometry(QtCore.QRect(280, 180, 112, 31))
self.label_hetongxinxi.setObjectName("label_hetongxinxi")
self.lineout10 = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.lineout10.setGeometry(QtCore.QRect(20, 210, 651, 20))
self.lineout10.setLineWidth(2)
self.lineout10.setFrameShape(QtWidgets.QFrame.HLine)
self.lineout10.setFrameShadow(QtWidgets.QFrame.Sunken)
self.lineout10.setObjectName("lineout10")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.daoru = QtWidgets.QPushButton(self.centralwidget)
self.daoru.setGeometry(QtCore.QRect(50, 710, 141, 41))
font = QtGui.QFont()
font.setFamily("幼圆")
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.daoru.setFont(font)
self.daoru.setObjectName("daoru")
self.baocun = QtWidgets.QPushButton(self.centralwidget)
self.baocun.setGeometry(QtCore.QRect(230, 710, 141, 41))
font = QtGui.QFont()
font.setFamily("幼圆")
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.baocun.setFont(font)
self.baocun.setObjectName("baocun")
self.fanhui = QtWidgets.QPushButton(self.centralwidget)
self.fanhui.setGeometry(QtCore.QRect(410, 710, 141, 41))
font = QtGui.QFont()
font.setFamily("幼圆")
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.fanhui.setFont(font)
self.fanhui.setObjectName("fanhui")
self.chongzhi = QtWidgets.QPushButton(self.centralwidget)
self.chongzhi.setGeometry(QtCore.QRect(590, 710, 141, 41))
font = QtGui.QFont()
font.setFamily("幼圆")
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.chongzhi.setFont(font)
self.chongzhi.setObjectName("chongzhi")
Table.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(Table)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
Table.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(Table)
self.statusbar.setObjectName("statusbar")
Table.setStatusBar(self.statusbar)
self.FilePath = ''
self.Old = 0
self.h=2
self.path = '文件管理.xlsx'
self.sheetname = '亚洲'
self.daoru.clicked.connect(self.DaoRuFile)
self.chongzhi.clicked.connect(self.clearing)
self.baocun.clicked.connect(self.Saving)
self.fanhui.clicked.connect(self.OpenFile)
self.retranslateUi(Table)
QtCore.QMetaObject.connectSlotsByName(Table)
def showDetails(self,actualpath, actualsheetname,actualh):
self.note = NoteBook(actualpath, actualsheetname)
for j,ind,infos in zip(range(len(self.note.index)),self.note.index,self.note.eachContract(actualh)):
exec('''
try:self.subline{i}.deleteLater()
except:pass
self.subline{i} = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.subline{i}.setGeometry(QtCore.QRect(50, {x}, 611, 16))
self.subline{i}.setFrameShape(QtWidgets.QFrame.HLine)
self.subline{i}.setFrameShadow(QtWidgets.QFrame.Sunken)
self.subline{i}.setObjectName("subline{i}")
try:self.label_no{i}.deleteLater()
except:pass
self.label_no{i} = QtWidgets.QLabel(self.scrollAreaWidgetContents)
self.label_no{i}.setGeometry(QtCore.QRect(60, {y}, 96, 18))
font = QtGui.QFont()
font.setFamily("楷体")
font.setBold(False)
font.setWeight(50)
self.label_no{i}.setFont(font)
self.label_no{i}.setObjectName("label_no{i}")
self.label_no{i}.setText("<html><head/><body><p><span style=' font-size:14pt;'>{ind}</span></p></body></html>")
self.label_no{i}.setToolTip("{ind}")
try:self.lineEdit_{i}.deleteLater()
except:pass
self.lineEdit_{i} = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
self.lineEdit_{i}.setGeometry(QtCore.QRect(170, {z}, 481, 30))
font = QtGui.QFont()
font.setFamily("楷体")
font.setPointSize(14)
self.lineEdit_{i}.setAlignment(Qt.AlignJustify)
self.lineEdit_{i}.setFont(font)
self.lineEdit_{i}.setObjectName("lineEdit_{i}")
self.lineEdit_{i}.setText("{infos}")
self.lineEdit_{i}.setToolTip("{infos}")
self.lineEdit_{i}.setCursorPosition(0)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -7, 709, {w}))
'''.format(i=j+1,x=60+j*50,y=40+j*50,z=30+j*50,w=80+j*50,infos=str(infos).replace('\n',' '),ind=ind))
def clearing(self):
for j in range(len(self.note.index)):
exec('self.lineEdit_{i}.clear()'.format(i=j+1))
def DaoRuFile(self):
if self.pathlabel.text()=='':
fname = QFileDialog.getOpenFileName(self, '打开文件','./')
else:
fname = QFileDialog.getOpenFileName(self, '打开文件', self.pathlabel.text())
if fname[0]:
self.FilePath = fname[0]
print(fname[0])
print(re.findall("(.*)/",fname[0])[0])
self.pathlabel.setText(re.findall("(.*)/",fname[0])[0])
self.chongzhi.click()
document = ReadDoc(fname[0])
self.lineEdit_2.setText(document.L2)
self.lineEdit_3.setText(document.L3)
self.lineEdit_4.setText(document.L4)
self.lineEdit_5.setText(document.L5)
self.lineEdit_6.setText(document.L6)
self.lineEdit_7.setText(document.L7)
self.lineEdit_8.setText(document.L8)
self.lineEdit_9.setText(document.L9)
def Saving(self):
mgbox = QMessageBox.question(self,'确认一下啊', '是否确定保存?', QMessageBox.Yes|QMessageBox.No,QMessageBox.No)
if mgbox==QMessageBox.No:
pass
else:
data=[]
print(self.lineEdit_1.text())
if self.Old==1 and self.lineEdit_1.text() =="":
wb2 = load_workbook(self.path)
ws=wb2[self.sheetname]
data.append(ws.max_row)
for j in range(len(self.note.index)-1):
exec('data.append(self.lineEdit_{i}.text())'.format(i=j+2))
ws.append(data)
wb2.save(self.path)
mgbox = QMessageBox.information(self,'恭喜','保存成功(新增)',QMessageBox.Ok)
elif self.Old==0 and self.lineEdit_1.text() !="":
for j in range(len(self.note.index)):
exec('data.append(self.lineEdit_{i}.text())'.format(i=j + 1))
wb2 = load_workbook(self.path)
ws=wb2[self.sheetname]
k = 1
for item in data:
try:
item = item.replace(' 00:00:00','')
except:
pass
print(self.h)
ws.cell(self.h+2,k,item)
k+=1
wb2.save(self.path)
mgbox = QMessageBox.information(self,'提示','保存成功(覆盖第{}行)'.format(self.h+2),QMessageBox.Ok)
else:
mgbox = QMessageBox.information(self, '提示', '出错了', QMessageBox.Ok)
def OpenFile(self):
if self.FilePath=='':
quest = QMessageBox.information(self, '找不到文件', '找不到文件', QMessageBox.Ok)
else:
os.startfile(self.FilePath)
def retranslateUi(self, Table):
_translate = QtCore.QCoreApplication.translate
Table.setWindowTitle(_translate("Table", "合同详细信息"))
self.label.setText(_translate("Table", "<html><head/><body><p><span style=\" font-size:28pt; font-weight:600;\">合同详细信息</span></p></body></html>"))
self.baocun.setText(_translate("Table", "保 存"))
self.fanhui.setText(_translate("Table", "打开文件"))
self.daoru.setText(_translate("Table", "导 入"))
self.chongzhi.setText(_translate("Table", "重 置"))
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow1 = QMainWindow()
ui = eachTable_MainWindow()
ui.setupUi(MainWindow1)
MainWindow1.show()
sys.exit(app.exec_())