# -*- coding: utf-8 -*- try: import xlrd except ImportError as e: print("%s 未安装xlrd,请pip install xlrd" %e) exit() import os from tkinter import * import tkinter.filedialog # def get_excel_path(): # excel_path=input('输入excel文件绝对路径:') # if not os.path.exists(excel_path): # print("%s 不存在!!!" %excel_path) # else: # return excel_path def get_excel_path(): default_dir = r"C:" # 设置默认打开目录 excel_path = tkinter.filedialog.askopenfilename(title=u"选择文件", initialdir=(os.path.expanduser(default_dir))) return excel_path def get_ecs_rds(excel_path): excel=xlrd.open_workbook(excel_path) table=excel.sheet_by_index(1) # print("name:%s,rows:%s,cols:%s" %(table.name,table.nrows,table.ncols)) rds = [] ecs = [] for i in range(table.nrows): if str(table.cell_value(i,1)).replace(".0","").isdigit() and table.cell_value(i,2): if str(table.cell_value(i,11)).replace(".0","").isdigit() : rds.append(table.row_values(i)) else: ecs.append(table.row_values(i)) return ecs,rds def print_text(ecs,rds): for Row_values in ecs: print("--------- 序号: %d ------------" % Row_values[1]) print("条线-一级部门:%s-%s" % (Row_values[6], Row_values[7])) print("实例名称: %s_%s_%s" % (Row_values[4], Row_values[9], Row_values[8])) print("ECS规格: %s" % Row_values[11]) print("系统类型: %s" % Row_values[10]) print(str("基础配置: %s/%s/%s/%s/%s(峰值)" % tuple(Row_values[12:17])).replace(".0", "")) print(("购买期限: %s月" % Row_values[3]).replace(".0", "")) for Row_values in rds: print("--------- 序号: %d ------------" % Row_values[1]) print("条线-一级部门:%s-%s" % (Row_values[5], Row_values[6])) print("实例名称: %s_%s_%s" % (Row_values[4], Row_values[8], Row_values[7])) print("RDS规格: %s" % Row_values[10]) print("数据库类型: %s" % Row_values[9]) print(str("基础配置: %s/%s/%s" % tuple(Row_values[11:14])).replace(".0", "")) print(("购买期限: %s月" % Row_values[3]).replace(".0", "")) if __name__ == '__main__': # excel_path = r'D:上传 41320180412-阿里云资源申请表-玖理基金APP-邢延昭 .xlsx' excel_path=get_excel_path() if excel_path: ecs,rds=get_ecs_rds(excel_path) # print("rds:%s ecs:%s" %(rds,ecs)) print_text(ecs, rds)
编辑对象是链接中的文件:链接: https://pan.baidu.com/s/1moa8aQmpKYkvtoGy71vpqA 密码: 6m4c