def mess(str): logger.loggerprint("开始读取xls,获取信息") wb = xlrd.open_workbook(r"C:\Users\Administrator\Desktop\来文来电\2019.xls") ws = wb.sheet_by_name(str) #print(wb.sheet_names()) list = [] if ws.cell_value(4, 0) == '会议时间': list = [ws.cell_value(2, 1),\ ws.cell_value(2, 3),\ ws.cell_value(3, 1),\ ws.cell_value(4, 1),\ ws.cell_value(4, 3),\ ws.cell_value(5, 1),\ ws.cell_value(7, 1),\ ws.cell_value(8, 1)] logger.loggerprint("确定有'会议时间',获取到的信息是:") logger.loggerprint(list) else: list = [ws.cell_value(2, 1), \ ws.cell_value(2, 3), \ ws.cell_value(3, 1), \ ws.cell_value(4, 1), \ ws.cell_value(6, 1), \ ws.cell_value(7, 1)] logger.loggerprint("确定无'会议时间',获取到的信息是:") logger.loggerprint(list) return list
def getsheets(): wb = xlrd.open_workbook(r"C:\Users\Administrator\Desktop\来文来电\2019.xls") list = wb.sheet_names() logger.loggerprint("获取sheet列表,getsheets()是:") logger.loggerprint(list) return list
def getno(): #wb = xlrd.open_workbook("C:\\Users\\Administrator\\Desktop\\相关工作\\来文来电\\2019.xls") #list = wb.sheet_names() list = getsheets() str = list[-1] logger.loggerprint("获取到的收文号,getno()是:", + str[str.find('-')+1:]) #print(str[str.find('-')+1:]) return str[str.find('-')+1:]
def init(): logger.loggerprint("进入初始化填写界面功能,init()") aptnameEntry.delete(0, END) timeEntry.delete(0, END) inpaperText.delete(0.0, END) meettimeEntry.delete(0, END) meetaddrEntry.delete(0, END) contentText.delete(0.0, END) planEntry.delete(0, END) planText.delete(0.0, END) logger.loggerprint("初始化填写界面完毕")
def timecall(): logger.loggerprint('进入是否精确功能,timecall()') timeEntry.delete(0, END) if v.get() == 1: logger.loggerprint("是否精确,选择的‘是’") timeEntry.insert(0, "%d年%d月%d日\n%s" % (time.localtime().tm_year, \ time.localtime().tm_mon, \ time.localtime().tm_mday,\ time.strftime("%H:%M",time.localtime()))) logger.loggerprint("timecall()完毕") elif v.get() == 0: logger.loggerprint("是否精确,选择的‘否’") timeEntry.insert(0, "%d年%d月%d日" % (time.localtime().tm_year, \ time.localtime().tm_mon, \ time.localtime().tm_mday)) logger.loggerprint("timecall()完毕") else: message("我也不知道怎么会到这一步")
def initbox(): logger.loggerprint("进入初始化下拉菜单功能,initbox()") xlsxlist = rxls.getsheets() logger.loggerprint("进入初始化下拉菜单功能,initbox()") xlsxCombobox["values"] = tuple(xlsxlist) xlsxCombobox.current(len(xlsxlist) - 1) xlsxCombobox["state"] = "readonly" xlsxCombobox.place(x=5, y=5) logger.loggerprint("重新初始化下拉菜单成功")
def insert(list): logger.loggerprint("写入access数据库,开始") db = 'Driver={Microsoft Access Database (*.mdb,*.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\来文来电\\2019.mdb' conn = pypyodbc.win_connect_mdb(db) curser = conn.cursor() sql_insert = '''INSERT INTO 2019(ID,来文单位,来文日期,来文名称,主要内容) VALUES(?,?,?,?,?)''' insert_value = (list[0], list[1], list[2], list[3], list[4]) logger.loggerprint("sql语句:" + sql_insert + insert_value) #print(list) #(ID,来文单位,来文日期,来文名称,主要内容,备注) curser.execute(sql_insert, insert_value) #curser.execute("INSERT INTO 2019(ID,来文单位,来文日期,来文名称,主要内容) VALUES('100', 'asd', 'asd', 'asd', 'asd')") conn.commit() # 没他不报错,也不插入,因为没有这条语句,折腾了一天,我日他娘。 conn.close() logger.loggerprint("写入access数据库,完毕")
def shutdown(): logger.loggerprint("--------关闭界面--------") root.destroy()
def printxls(): logger.loggerprint("进入打印功能,printxls()") logger.loggerprint("进入打印功能,下拉菜单选项,确定打印哪个") sortstr = xlsxCombobox.get() logger.loggerprint("打印的是:" + sortstr) list = [sortstr[5:]] + rxls.mess(sortstr) logger.loggerprint("内容是:") logger.loggerprint(list) if len(list) == 9: w2xls.tempfilewithmeeting(list) logger.loggerprint("创建有会议的tempfile成功") elif len(list) == 7: w2xls.tempfilewithoutmeeting(list) logger.loggerprint("创建无会议的tempfile成功") function.printer('C:\\tempfile.xls') logger.loggerprint("打印完毕") message('打印成功')
def saveandprint(): logger.loggerprint("进入保存并且打印功能") save() printxls() logger.loggerprint("完成保存并且打印功能")
def save(): logger.loggerprint("进入保存功能,save()") aptname = aptnameEntry.get() time = timeEntry.get() inpaper = inpaperText.get('1.0', END)[:-1] #这里加[:-1]是为了删除最后多出来的换行符 meettime = meettimeEntry.get() meetaddr = meetaddrEntry.get() content = contentText.get('1.0', END)[:-1] plan = planEntry.get() plan1 = planText.get('1.0', END)[:-1] logger.loggerprint("保存前(判断前)获取信息如下:") logger.loggerprint([ aptname, time, inpaper, meettime, meetaddr, content, plan, plan1 ]) if aptname == "" and inpaper == "" and content == "": message('请填写信息!!!') elif meettime == '': no = int(rxls.getno()) + 1 list = [no, aptname, time, inpaper, content, plan, plan1] #print(no) logger.loggerprint("保存前(没会)获取信息如下:") logger.loggerprint(list) w2xls.withoutmeeting(list) w2xls.tempfilewithoutmeeting(list) w2accdb.insert(list) logger.loggerprint("保存完毕,重新初始化下拉框之前") initbox() # 将保存好的sheet显示在下拉框里 logger.loggerprint("保存完毕,重新初始化下拉框之后") message('保存成功') else: no = int(rxls.getno()) + 1 list = [ no, aptname, time, inpaper, meettime, meetaddr, content, plan, plan1 ] # print(no) logger.loggerprint("保存前(有会)获取信息如下:") logger.loggerprint(list) w2xls.withmeeting(list) w2xls.tempfilewithmeeting(list) w2accdb.insert(list) logger.loggerprint("保存完毕,重新初始化下拉框之前") initbox() # 将保存好的sheet显示在下拉框里 logger.loggerprint("保存完毕,重新初始化下拉框之后") message('保存成功') """
def sort(): logger.loggerprint('进入查询功能,sort()') init() sortstr = xlsxCombobox.get() logger.loggerprint('下拉菜单选择的是:') logger.loggerprint(sortstr) #print('sort',sortstr) list = rxls.mess(sortstr) logger.loggerprint('查询到的信息是:') logger.loggerprint(list) #scanview() if len(list) == 8: aptnameEntry.insert(0, list[0]) timeEntry.insert(0, list[1]) inpaperText.insert(INSERT, list[2]) meettimeEntry.insert(0, list[3]) meetaddrEntry.insert(0, list[4]) contentText.insert(INSERT, list[5]) planEntry.insert(0, list[6]) planText.insert(INSERT, list[7]) logger.loggerprint('有会议,插入成功,查询完毕') elif len(list) == 6: aptnameEntry.insert(0, list[0]) timeEntry.insert(0, list[1]) inpaperText.insert(INSERT, list[2]) contentText.insert(INSERT, list[3]) planEntry.insert(0, list[4]) planText.insert(INSERT, list[5]) logger.loggerprint('无会议,插入成功,查询完毕')
#查询按钮 checkbutton = Button(self.xlsxFrame, text='查询(Q)', command=sort) checkbutton.place(x=180, y=0) self.xlsxFrame.place(x=270, y=0) # 按钮 self.action1 = ttk.Button(object, text="保存(S)", command=save) # 创建一个按钮, text self.action1.place(x=70, y=550) # 按钮 self.action2 = ttk.Button(object, text="保存并打印(S&P)", command=saveandprint) # 创建一个按钮, text self.action2.place(x=230, y=550) # 按钮 self.action3 = ttk.Button(object, text="打印(P)", command=printxls) # 创建一个按钮, text self.action3.place(x=400, y=550) # 按钮 self.action4 = ttk.Button(object, text="关闭(C)", command=shutdown) # 创建一个按钮, text self.action4.place(x=560, y=550) root = Tk() root.title("来文阅办信息化管理系统") root.geometry("800x600") root.geometry("+500+200") app = App(root) logger.loggerprint("------------开始-----------") root.mainloop()
def printer(file): logger.loggerprint("开始打印功能,打印的是:") logger.loggerprint(file) filename = file win32api.ShellExecute(0, "print", filename, '/d:"%s"' % win32print.GetDefaultPrinter(), ".", 0)
def withmeeting(list): logger.loggerprint("有会议,写入xls,开始") rb = xlrd.open_workbook(r"C:\Users\Administrator\Desktop\来文来电\2019.xls", formatting_info=True) wb = copy(rb) ws = wb.add_sheet('2019-' + str(list[0])) # 设置字体,字号(仿宋_GB2312,14)song_font song_font = xlwt.Font() song_font.name = '仿宋_GB2312' song_font.height = 280 # 字体大小,220就是11号字体,大概就是11*20得来的吧 # 设置字体,字号(黑体,14)black_font black_font = xlwt.Font() black_font.name = '黑体' black_font.height = 280 # 设置字体,字号(方正小标宋_GBK,20)black_font1 black_font1 = xlwt.Font() black_font1.name = '方正小标宋_GBK' black_font1.height = 400 # 设置边框(上下左右) all_border = xlwt.Borders() # 给单元格加框线 all_border.left = xlwt.Borders.THIN # 左 all_border.top = xlwt.Borders.THIN # 上 all_border.right = xlwt.Borders.THIN # 右 all_border.bottom = xlwt.Borders.THIN # 下 all_border.left_colour = 0x40 # 设置框线颜色,0x40是黑色,颜色真的巨多,都晕了 all_border.right_colour = 0x40 all_border.top_colour = 0x40 all_border.bottom_colour = 0x40 # 设置边框(上下右) udr_border = xlwt.Borders() # 给单元格加框线 udr_border.top = xlwt.Borders.THIN # 上 udr_border.right = xlwt.Borders.THIN # 右 udr_border.bottom = xlwt.Borders.THIN # 下 # 设置框线颜色,0x40是黑色,颜色真的巨多,都晕了 udr_border.right_colour = 0x40 udr_border.top_colour = 0x40 udr_border.bottom_colour = 0x40 # 设置边框(上) u_border = xlwt.Borders() # 给单元格加框线 u_border.top = xlwt.Borders.THIN # 上 u_border.top_colour = 0x40 # 设置边框(上下) ud_border = xlwt.Borders() # 给单元格加框线 ud_border.top = xlwt.Borders.THIN # 上 ud_border.bottom = xlwt.Borders.THIN # 下 ud_border.top_colour = 0x40 # 上 ud_border.bottom_colour = 0x40 # 下 # 自动换行,水平垂直居中 wrap_mid_al = xlwt.Alignment() wrap_mid_al.horz = 0x02 # 设置水平居中 wrap_mid_al.vert = 0x01 # 设置垂直居中 wrap_mid_al.wrap = 1 # 自动换行,水平居左,垂直居中 wrap_left_al = xlwt.Alignment() wrap_left_al.horz = 0x01 # 设置水平居左 wrap_left_al.vert = 0x01 # 设置垂直居中 wrap_left_al.wrap = 1 # 不换行,水平居左,垂直居中 nowrap_left_al = xlwt.Alignment() nowrap_left_al.horz = 0x01 # 设置水平居左 nowrap_left_al.vert = 0x01 # 设置垂直居中 # 黑体14号字,水平垂直居中,自动换行,上下右边框 # 来文单位,来文名称,主要内容,领导批示,拟办意见,处理结果 black_mid_wrap_udr_style = xlwt.XFStyle() black_mid_wrap_udr_style.alignment = wrap_mid_al black_mid_wrap_udr_style.font = black_font black_mid_wrap_udr_style.borders = udr_border # 黑体14号字,水平垂直居中,自动换行,全边框 # 收文时间,会议地点 black_mid_wrap_all_style = xlwt.XFStyle() black_mid_wrap_all_style.alignment = wrap_mid_al black_mid_wrap_all_style.font = black_font black_mid_wrap_all_style.borders = all_border # 仿宋GB2312,14号字,水平垂直居中,自动换行,仅上框 # 来文单位,来文名称,领导批示,收文时间,会议地点 # 上面的那些内容 song_mid_wrap_u_style = xlwt.XFStyle() song_mid_wrap_u_style.alignment = wrap_mid_al song_mid_wrap_u_style.font = song_font song_mid_wrap_u_style.borders = u_border # 仿宋GB2312,14号字,垂直居中,水平居左,自动换行,仅上框 # 主要内容,拟办意见 # 上面的那些内容 song_left_wrap_u_style = xlwt.XFStyle() song_left_wrap_u_style.alignment = wrap_left_al song_left_wrap_u_style.font = song_font song_left_wrap_u_style.borders = u_border # 仿宋GB2312,14号字,垂直居中,水平居左,自动换行,上下框 # 处理结果 # 内容 song_left_wrap_ud_style = xlwt.XFStyle() song_left_wrap_ud_style.alignment = wrap_left_al song_left_wrap_ud_style.font = song_font song_left_wrap_ud_style.borders = ud_border # 黑体14号,垂直居中,水平居左,不换行,无框 # 紧急程度,省总工会办公室,承办人:张腾 black_left_nowrap_nobord_style = xlwt.XFStyle() black_left_nowrap_nobord_style.alignment = nowrap_left_al black_left_nowrap_nobord_style.font = black_font # 宋体14号,垂直居中,水平居左,换行,无框 # 收文号 song_left_nowrap_nobord_style = xlwt.XFStyle() song_left_nowrap_nobord_style.alignment = wrap_left_al song_left_nowrap_nobord_style.font = song_font # 方正小标宋_GBK 20号,水平垂直居中,换行,无框 # 山西省总工会来文、来电阅办卡片 black_mid_wrap_nobord_style = xlwt.XFStyle() black_mid_wrap_nobord_style.alignment = wrap_mid_al black_mid_wrap_nobord_style.font = black_font1 # 设置单元格宽度 ws.col(0).width = 3500 ws.col(1).width = 8000 ws.col(2).width = 4500 ws.col(3).width = 8000 ws.row(0).set_style(xlwt.easyxf('font:height 600;')) # 行高37.5 ws.row(1).set_style(xlwt.easyxf('font:height 650;')) # 行高40.5 ws.row(2).set_style(xlwt.easyxf('font:height 650;')) ws.row(3).set_style(xlwt.easyxf('font:height 700;')) ws.row(4).set_style(xlwt.easyxf('font:height 700;')) ws.row(5).set_style(xlwt.easyxf('font:height 3000;')) # 行高180 ws.row(6).set_style(xlwt.easyxf('font:height 3000;')) # 行高180 ws.row(7).set_style(xlwt.easyxf('font:height 650;')) # 行高40.5 ws.row(8).set_style(xlwt.easyxf('font:height 780;')) # 行高50 ws.row(9).set_style(xlwt.easyxf('font:height 480;')) # 行高30 ws.row(10).set_style(xlwt.easyxf('font:height 570;')) # 行高30 ws.row(11).set_style(xlwt.easyxf('font:height 300;')) # 行高18 ws.write(0, 0, '紧急程度:', black_left_nowrap_nobord_style) ws.write(0, 3, ' 收文号:[2019]' + str(list[0]), song_left_nowrap_nobord_style) ws.write_merge(1, 1, 0, 3, '山西省总工会来文、来电阅办卡片', black_mid_wrap_nobord_style) ws.write(2, 0, '来文单位', black_mid_wrap_udr_style) ws.write(2, 1, list[1], song_mid_wrap_u_style) ws.write(2, 2, '收文时间', black_mid_wrap_all_style) ws.write(2, 3, list[2], song_mid_wrap_u_style) ws.write(3, 0, '来文名称', black_mid_wrap_udr_style) ws.write_merge(3, 3, 1, 3, list[3], song_mid_wrap_u_style) ws.write(4, 0, '会议时间', black_mid_wrap_udr_style) ws.write(4, 1, list[4], song_mid_wrap_u_style) ws.write(4, 2, '会议地点', black_mid_wrap_all_style) ws.write(4, 3, list[5], song_mid_wrap_u_style) ws.write(5, 0, '主要内容', black_mid_wrap_udr_style) ws.write_merge(5, 5, 1, 3, list[6], song_left_wrap_u_style) ws.write(6, 0, '领\n导\n批\n示', black_mid_wrap_udr_style) ws.write_merge(6, 6, 1, 3, '', song_left_wrap_u_style) ws.write_merge(7, 9, 0, 0, '拟办意见', black_mid_wrap_udr_style) ws.write_merge(7, 7, 1, 3, list[7], song_left_wrap_u_style) ws.write_merge(8, 8, 1, 3, list[8], song_left_nowrap_nobord_style) ws.write(10, 0, '处理结果', black_mid_wrap_udr_style) ws.write_merge(10, 10, 1, 3, '', song_left_wrap_ud_style) ws.write(11, 0, ' 省总工会办公室', black_left_nowrap_nobord_style) # 5个空格 ws.write(11, 3, ' 承办人:张 腾', black_left_nowrap_nobord_style) wb.save(r"C:\Users\Administrator\Desktop\来文来电\2019.xls") logger.loggerprint("有会议,写入xls,完毕")