import os import win32com.client as win32 import shutil import openpyxl import time #####The first step is to drop the xlsx file in the original folder and copy it directly to the bak folder, slice rst fn ='balance sheet.xlsx' wb = openpyxl.load_workbook(fn) ws = wb.get_sheet_by_name("Balance Sheet") row_result = 0 column_result = 0 result = 0 #################### #########################Lock tax return and workbook # The following code is used to write the relevant data in multiple tables into the financial Status table def getdate(date_row, date_column): for row in ws.iter_rows(): for cell in row: for i in range(len(date_row)): #print(date_row[i]) if str(str(cell. value).replace('','')).find(date_row[i]) != -1: row_result = cell.row print(row_result) break for row in ws.iter_rows(): for cell in row: for i in range(len(date_column)): #print(date_row[i]) if str(str(cell.value).replace(' ', '')).find(date_column[i]) != -1: column_result = cell.column print(column_result) break print(ws.cell(row=row_result, column=column_result).value) if __name__ == '__main__': print("企业数和企业亏损情况") print(getdate(['存货','@'],['年初余额','@'])); ''' or inventory 1 year inventory 2 Total current assets or balance at the beginning of the yearat the beginning of Total current assets and total non-current assets or balance at the end of the period ########### Balance sheet 1 inventory at the beginning of the year for row in ws_fuzhaibiao.iter_rows(): for cell in row: if str(str(cell .value).replace('','')).find("Stock") != -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("Year balance") != -1 or str(str(cell.value).replace('','')) .find( " Beginning of the year") != -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 = round(float( str(wuc_fuzhain ',','')) / 1000) print(ws_fuzhaibiao_nianchucunhuo) ########### Balance Sheet 2 Total Current Assets for row in ws_fuzhaibiao.iter_rows(): for cell in row: # print( cell.value) if str(str(cell.lvalue).replace('','')).find("Total current assets") != -1 and str(cell.value).find("Non-current assets Total") == -1: liudongzichanheji_row = cell.row break for row in ws_fuzhaibiao.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find("期末余额") != -1 or str(str(cell.value).replace(' ', '')).find( "期末数") != -1: liudongzichanheji_column = cell.coumn # print(zichanheji_column) break if liudongzichanheji_row == 0 or liudongzichanheji_column == 0: ws_fuzhaibiao_liudongzichanheji = 0 else: if ws_fuzhaibiao.cell(row=liudongzichanheji_row, column=liudongzichanheji_column).value != None: ws_fuzhaibiao_liudongzichanheji = round(float( str(ws_fuzhaibiao.cell(row=liudongzichanheji_row, column=liudongzichanheji_column).value).replace(',', '')) / 1000) print(ws_fuzhaibiao_liudongzichanheji) ########################################资产负债表 应收账款 for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find(date_row) != -1: row_result = cell.row # print(row_result) else: result = 0 break for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find(date_column) != -1: column_result = cell.column # print(column_result) break # print(column_result) if row_result == 0 or column_result == 0: result = 0 else: if ws.cell(row=row_result, column=column_result).value != None: # print(column_result) result = ws.cell(row=row_result, column=column_result).value # print(result) return result '''
One-click statistics 5.0 submodule 01
Guess you like
Origin blog.csdn.net/jidawanghao/article/details/112967731
Recommended
Ranking