from openpyxl import load_workbook ''' @File : @Author : william @Time : 2020/09/29 @notice : null @coding : utf-8 ''' # import xlrd # from xlutils.copy import copy import openpyxl # 下一步还得训练程序 # 使其满足对excel文件名和excel工作薄的识别 ws_fuzhaibiao_nianchucunhuo = 0 nianchucunhuo_row = 0 nianchucunhuo_column = 0 #####################################################################锁定资产负债表和工作薄 # 如下代码用于多个相关表的打开操作 fn_fuzhaibiao = '资产负债表.xlsx' wb_fuzhaibiao = openpyxl.load_workbook(fn_fuzhaibiao) fuzhaibiao_allSheets = wb_fuzhaibiao.get_sheet_names() for i in range(len(fuzhaibiao_allSheets)): fuzhaibiao_sheet = wb_fuzhaibiao.get_sheet_by_name(fuzhaibiao_allSheets[i]) for row in fuzhaibiao_sheet.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("资产负债表") != -1: fuzhaibiao_sheet_selected = wb_fuzhaibiao.get_sheet_by_name(fuzhaibiao_allSheets[i]) break ws_fuzhaibiao = wb_fuzhaibiao.get_sheet_by_name(fuzhaibiao_sheet_selected.title) print(ws_fuzhaibiao) ########### 资产负债表 1年初存货 for row in ws_fuzhaibiao.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("总计") != -1: nianchucunhuo_row = cell.row else: ws_fuzhaibiao_nianchucunhuo = 0 break for row in ws_fuzhaibiao.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("企业数") != -1 : nianchucunhuo_column = cell.column break if nianchucunhuo_row == 0 or nianchucunhuo_column == 0: ws_fuzhaibiao_nianchucunhuo = 0 else: if ws_fuzhaibiao.cell(row=nianchucunhuo_row, column=nianchucunhuo_column).value != None: ws_fuzhaibiao_nianchucunhuo = ws_fuzhaibiao.cell(row=nianchucunhuo_row, column=nianchucunhuo_column).value print(ws_fuzhaibiao_nianchucunhuo)
简单的取值
猜你喜欢
转载自blog.csdn.net/jidawanghao/article/details/112808377
今日推荐
周排行