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 # Next Also have to train program # to make it meet the recognition of excel file name and excel workbook ws_fuzhaibiao_nianchucunhuo = 0 nianchucunhuo_row = 0 nianchucunhuo_column = 0 ####################### ############################################Lock the balance sheet and Workbook # The following code is used to open multiple related tables fn_fuzhaibiao ='Balance Sheet.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("Number of enterprises") != -1: nianchucunhuo_column = cell.column break if nianchucunhuo_row == 0 or nianchucunhuo_column == 0: ws_fuzhaibiao_nianchucunhuo = 0 else: if ws_fuzhaibiao.cell(row=niaonchucunhuo_row, column=nia =niaonchucunhuo_n , column=nianchucunhuo_column).value print(ws_fuzhaibiao_nianchucunhuo)
Simple value
Guess you like
Origin blog.csdn.net/jidawanghao/article/details/112808377
Recommended
Ranking