一键式统计5.0子模块01

import os
import win32com.client as win32
import shutil
import openpyxl

import time

#####第一步先降原文件夹中的xlsx文件直接拷贝至bak文件夹中,切片r s t


fn = '资产负债表.xlsx'
wb = openpyxl.load_workbook(fn)

ws = wb.get_sheet_by_name("资产负债表")

row_result = 0
column_result = 0
result = 0

################################################锁定纳税申报表和工作薄


# 如下代码用于将多个表中的相关数据写入财务状况表


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(['存货','@'],['年初余额','@']));

'''

1年初存货
or   存货
or   年初余额  年初数

2流动资产合计
流动资产合计  and   非流动资产合计
or   期末余额  期末数


########### 资产负债表     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 or 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 = round(float(
            str(ws_fuzhaibiao.cell(row=nianchucunhuo_row, column=nianchucunhuo_column).value).replace(',', '')) / 1000)
        print(ws_fuzhaibiao_nianchucunhuo)

########### 资产负债表    2流动资产合计

for row in ws_fuzhaibiao.iter_rows():
    for cell in row:
        # print(cell.value)
        if str(str(cell.lvalue).replace(' ', '')).find("流动资产合计") != -1 and str(cell.value).find("非流动资产合计") == -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



'''

猜你喜欢

转载自blog.csdn.net/jidawanghao/article/details/112967731