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 # The next step is to train the program # Make it meet the recognition of excel file name and excel workbook ws_qiyeshu = 0 qiyeshu_row = 0 qiyeshu_column = 0 ws_zichanofficer = 0 zichanofficer_row = 0 zichanofficer_column = 0 ############################################## ###################Lock the balance sheet and workbook # The following code is used to open multiple related tables fn ='Balance Sheet.xlsx' wb = openpyxl.load_workbook(fn) allSheets = wb.get_sheet_names() for i in range(len(allSheets)): sheet = wb.get_sheet_by_name(allSheets[i]) for row in sheet.iter_rows(): for cell in row: if str(str(cell.value).replace('','')).find("Balance Sheet") != -1: sheet_selected = wb.get_sheet_by_name(allSheets[i]) break ws = wb.get_sheet_by_name(sheet_selected.title) print(ws) ########### Balance sheet inventory at the beginning of 1 for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("总计") != -1: qiyeshu_row = cell.row else: ws_qiyeshu = 0 break for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("企业数") != -1 : qiyeshu_column = cell.column break if qiyeshu_row == 0 or qiyeshu_column == 0: ws_qiyeshu = 0 else: if ws.cell(row=qiyeshu_row, column=qiyeshu_column).value != None: ws_qiyeshu = ws.cell(row=qiyeshu_row, column=qiyeshu_column).value print(ws_qiyeshu) for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("总计") != -1: zichanzongji_row = cell.row else: ws_zichanofficer = 0 break for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace('','')).find("Total Assets") != -1: zichanzongji_column = cell.column break if zichanzongji_row == 0 or zichanzongji_column == 0: ws_zichanofficer = 0 else: if ws.cell(row=zichanzongji_row, column=zichanzongji_column).value != None: ws_zichanofficer = ws.cell(row=zichanofficer_row, column=zichanofficer_column).value print(ws_zichanofficer)
Quarterly financial report---focus on content 02
Guess you like
Origin blog.csdn.net/jidawanghao/article/details/112819332
Ranking