财务季报评估报告数据自动生成1.0

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 = 0
row_result = 0
column_result = 0
result = 0


#####################################################################锁定资产负债表和工作薄
# 如下代码用于多个相关表的打开操作
fn = '资产负债表.xlsx'
wb = openpyxl.load_workbook(fn)



ws = wb.get_sheet_by_name('资产负债表')
#print(ws)


def getdate(date_row,date_column):
   # print(date_row)
   # print(date_column)

    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


def getdate_lastyear(date_row,date_column):
   # print(date_row)
   # print(date_column)

    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 + 1
              #  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



def getspeed(date_row,date_column):
   # print(date_row)
   # print(date_column)

    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 + 2
              #  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


if __name__ == '__main__':
    print("企业数和企业亏损情况")
    print(round(getdate('总计','企业数'),1));



    print('资产情况')

    print(round(getdate('总计','资产总计'),1));
    print(round(getspeed('总计', '资产总计'),1));

    print(round(getdate('一、批发业', '资产总计'),1));
    print(round(getspeed('一、批发业', '资产总计'),1));

    print(round(getdate('二、零售业', '资产总计'),1));
    print(round(getspeed('二、零售业', '资产总计'),1));

    print(round(getdate('三、住宿业', '资产总计'),1));
    print(round(getspeed('三、住宿业', '资产总计'),1));

    print(round(getdate('四、餐饮业', '资产总计'),1));
    print(round(getspeed('四、餐饮业', '资产总计'),1));

    print('负债情况')

    print(round(getdate('总计','负债合计'),1));
    print(round(getspeed('总计', '负债合计'),1));

    print(round(getdate('一、批发业', '负债合计'),1));
    print(round(getspeed('一、批发业', '负债合计'),1));

    print(round(getdate('二、零售业', '负债合计'),1));
    print(round(getspeed('二、零售业', '负债合计'),1));

    print(round(getdate('三、住宿业', '负债合计'),1));
    print(round(getspeed('三、住宿业', '负债合计'),1));

    print(round(getdate('四、餐饮业', '负债合计'),1));
    print(round(getspeed('四、餐饮业', '负债合计'),1));

    print('营业收入')

    print(round(getdate('总计','营业收入'),1));
    print(round(getspeed('总计', '营业收入'),1));

    print(round(getdate('一、批发业', '营业收入'),1));
    print(round(getspeed('一、批发业', '营业收入'),1));

    print(round(getdate('二、零售业', '营业收入'),1));
    print(round(getspeed('二、零售业', '营业收入'),1));

    print(round(getdate('三、住宿业', '营业收入'),1));
    print(round(getspeed('三、住宿业', '营业收入'),1));

    print(round(getdate('四、餐饮业', '营业收入'),1));
    print(round(getspeed('四、餐饮业', '营业收入'),1));

    print('营业成本')

    print(round(getdate('总计','营业成本'),1));
    print(round(getspeed('总计', '营业成本'),1));

    print(round(getdate('一、批发业', '营业成本'),1));
    print(round(getspeed('一、批发业', '营业成本'),1));

    print(round(getdate('二、零售业', '营业成本'),1));
    print(round(getspeed('二、零售业', '营业成本'),1));

    print(round(getdate('三、住宿业', '营业成本'),1));
    print(round(getspeed('三、住宿业', '营业成本'),1));

    print(round(getdate('四、餐饮业', '营业成本'),1));
    print(round(getspeed('四、餐饮业', '营业成本'),1));

    print('营业税金')

    print(round(getdate('总计','税金及附加'),1));
    print(round(getspeed('总计', '税金及附加'),1));

    print(round(getdate('一、批发业', '税金及附加'),1));
    print(round(getspeed('一、批发业', '税金及附加'),1));

    print(round(getdate('二、零售业', '税金及附加'),1));
    print(round(getspeed('二、零售业', '税金及附加'),1));

    print(round(getdate('三、住宿业', '税金及附加'),1));
    print(round(getspeed('三、住宿业', '税金及附加'),1));

    print(round(getdate('四、餐饮业', '税金及附加'),1));
    print(round(getspeed('四、餐饮业', '税金及附加'),1));




    print('四项费用')


    print(round(getdate('总计','销售费用')+getdate('总计','管理费用')+getdate('总计','研发费用')+getdate('总计','财务费用'),1));


    print(
      round(  ((getdate('总计','销售费用')+getdate('总计','管理费用')+getdate('总计','研发费用')+getdate('总计','财务费用'))/(getdate_lastyear('总计','销售费用')+getdate_lastyear('总计','管理费用')+getdate_lastyear('总计','研发费用')+getdate_lastyear('总计','财务费用'))- 1)*100,1)
    )

    print(round(getdate('一、批发业','销售费用')+getdate('一、批发业','管理费用')+getdate('一、批发业','研发费用')+getdate('一、批发业','财务费用'),1));
    print(
      round(  ((getdate('一、批发业','销售费用')+getdate('一、批发业','管理费用')+getdate('一、批发业','研发费用')+getdate('一、批发业','财务费用'))/(getdate_lastyear('一、批发业','销售费用')+getdate_lastyear('一、批发业','管理费用')+getdate_lastyear('一、批发业','研发费用')+getdate_lastyear('一、批发业','财务费用'))- 1)*100,1)
    )

    print(round(getdate('二、零售业','销售费用')+getdate('二、零售业','管理费用')+getdate('二、零售业','研发费用')+getdate('二、零售业','财务费用'),1));
    print(
      round(  ((getdate('二、零售业','销售费用')+getdate('二、零售业','管理费用')+getdate('二、零售业','研发费用')+getdate('二、零售业','财务费用'))/(getdate_lastyear('二、零售业','销售费用')+getdate_lastyear('二、零售业','管理费用')+getdate_lastyear('二、零售业','研发费用')+getdate_lastyear('二、零售业','财务费用'))- 1)*100,1)
    )
    print(round(getdate('三、住宿业','销售费用')+getdate('三、住宿业','管理费用')+getdate('三、住宿业','研发费用')+getdate('三、住宿业','财务费用'),1));
    print(
      round(  ((getdate('三、住宿业','销售费用')+getdate('三、住宿业','管理费用')+getdate('三、住宿业','研发费用')+getdate('三、住宿业','财务费用'))/(getdate_lastyear('三、住宿业','销售费用')+getdate_lastyear('三、住宿业','管理费用')+getdate_lastyear('三、住宿业','研发费用')+getdate_lastyear('三、住宿业','财务费用'))- 1)*100,1)
    )

    print(round(getdate('四、餐饮业','销售费用')+getdate('四、餐饮业','管理费用')+getdate('四、餐饮业','研发费用')+getdate('四、餐饮业','财务费用'),1));
    print(
      round(  ((getdate('四、餐饮业','销售费用')+getdate('四、餐饮业','管理费用')+getdate('四、餐饮业','研发费用')+getdate('四、餐饮业','财务费用'))/(getdate_lastyear('四、餐饮业','销售费用')+getdate_lastyear('四、餐饮业','管理费用')+getdate_lastyear('四、餐饮业','研发费用')+getdate_lastyear('四、餐饮业','财务费用'))- 1)*100,1)
    )



    print('营业利润')

    print(round(getdate('总计','营业利润'),1));
    print(round(getspeed('总计', '营业利润'),1));

    print(round(getdate('一、批发业', '营业利润'),1));
    print(round(getspeed('一、批发业', '营业利润'),1));

    print(round(getdate('二、零售业', '营业利润'),1));
    print(round(getspeed('二、零售业', '营业利润'),1));

    print(round(getdate('三、住宿业', '营业利润'),1));
    print(round(getspeed('三、住宿业', '营业利润'),1));

    print(round(getdate('四、餐饮业', '营业利润'),1));
    print(round(getspeed('四、餐饮业', '营业利润'),1));

    print('应交增值税')

    print(round(getdate('总计','应交增值税'),1));
    print(round(getspeed('总计', '应交增值税'),1));

    print(round(getdate('一、批发业', '应交增值税'),1));
    print(round(getspeed('一、批发业', '应交增值税'),1));

    print(round(getdate('二、零售业', '应交增值税'),1));
    print(round(getspeed('二、零售业', '应交增值税'),1));

    print(round(getdate('三、住宿业', '应交增值税'),1));
    print(round(getspeed('三、住宿业', '应交增值税'),1));

    print(round(getdate('四、餐饮业', '应交增值税'),1));
    print(round(getspeed('四、餐饮业', '应交增值税'),1));

    print('资产负债率')
    if (  getdate('总计','负债合计') >0  and getdate('总计','资产总计')   > 0 ):
        print(round(getdate('总计','负债合计')/getdate('总计','资产总计')*100,1));
    else:
        print("error")

    if (  getdate('总计','资产总计')   > 0 and getdate_lastyear('总计','资产总计') > 0 and getdate('总计','负债合计') > 0 and  getdate_lastyear('总计','负债合计') >0):
        print(round((getdate('总计','负债合计')/getdate('总计','资产总计')-getdate_lastyear('总计','负债合计')/getdate_lastyear('总计','资产总计'))*100,1));
    else:
        print("error")

    if (getdate('一、批发业','资产总计')> 0 and getdate('一、批发业','负债合计') > 0 ):
        print(round(getdate('一、批发业','负债合计')/getdate('一、批发业','资产总计')*100,1));
    else:
        print("error")
    if (    getdate('一、批发业','资产总计') > 0 and  getdate_lastyear('一、批发业','资产总计') >0 and getdate('一、批发业','负债合计')> 0 and getdate_lastyear('一、批发业','负债合计') >0  ):
        print(round((getdate('一、批发业','负债合计')/getdate('一、批发业','资产总计')-getdate_lastyear('一、批发业','负债合计')/getdate_lastyear('一、批发业','资产总计'))*100,1));
    else:
        print("error")

    if (  getdate('二、零售业','资产总计')> 0 and getdate('二、零售业','负债合计') > 0):
        print(round(getdate('二、零售业','负债合计')/getdate('二、零售业','资产总计')*100,1));
    else:
        print("error")

    if (getdate('二、零售业','资产总计')  > 0 and getdate_lastyear('二、零售业','资产总计') > 0  and getdate('二、零售业','负债合计') > 0 and getdate_lastyear('二、零售业','负债合计') > 0):
        print(round((getdate('二、零售业','负债合计')/getdate('二、零售业','资产总计')-getdate_lastyear('二、零售业','负债合计')/getdate_lastyear('二、零售业','资产总计'))*100,1));
    else:
        print("error")

    if (  getdate('三、住宿业','资产总计') > 0   and  getdate('三、住宿业','负债合计') > 0):
        print(round(getdate('三、住宿业','负债合计')/getdate('三、住宿业','资产总计')*100,1));
    else:
        print("error")

    if (getdate('三、住宿业','资产总计') > 0 and  getdate_lastyear('三、住宿业','资产总计') > 0  and getdate('三、住宿业','负债合计')>0 and getdate_lastyear('三、住宿业','负债合计')>0 ):
        print(round((getdate('三、住宿业','负债合计')/getdate('三、住宿业','资产总计')-getdate_lastyear('三、住宿业','负债合计')/getdate_lastyear('三、住宿业','资产总计'))*100,1));
    else:
        print("error")

    if ( getdate('三、住宿业','资产总计')> 0  and getdate('四、餐饮业','负债合计')> 0  ):
        print(round(getdate('四、餐饮业','负债合计')/getdate('三、住宿业','资产总计')*100,1));
    else:
        print("error")

    if (   getdate('四、餐饮业','资产总计')  > 0 and  getdate_lastyear('四、餐饮业','资产总计') >  0  and getdate('四、餐饮业','负债合计')>0 and getdate_lastyear('四、餐饮业','负债合计') >0):
        print(round((getdate('四、餐饮业','负债合计')/getdate('四、餐饮业','资产总计')-getdate_lastyear('四、餐饮业','负债合计')/getdate_lastyear('四、餐饮业','资产总计'))*100,1));
    else:
        print("error")
    print('毛利率')

    if (getdate('总计','营业收入') > 0 and getdate('总计','营业成本')>0 )  :
        print(round((1-getdate('总计','营业成本')/getdate('总计','营业收入'))*100,1));
    else:
        print("error")

    if (   getdate_lastyear('总计','营业收入')  > 0 and getdate('总计','营业收入') >  0 and getdate_lastyear('总计','营业成本') >0 and getdate('总计','营业成本') > 0 ):
        print(round((getdate_lastyear('总计','营业成本')/getdate_lastyear('总计','营业收入')-getdate('总计','营业成本')/getdate('总计','营业收入'))*100,1));
    else:
        print("error")

    if (getdate('一、批发业','营业收入') > 0  and  getdate('一、批发业','营业成本') > 0):
        print(round((1-getdate('一、批发业','营业成本')/getdate('一、批发业','营业收入'))*100,1));
    else:
        print("error")

    if (    getdate_lastyear('一、批发业','营业收入') > 0 and getdate('一、批发业','营业收入') > 0 and getdate_lastyear('一、批发业','营业成本')  > 0  and getdate('一、批发业','营业成本') > 0):
        print(round((getdate_lastyear('一、批发业','营业成本')/getdate_lastyear('一、批发业','营业收入')-getdate('一、批发业','营业成本')/getdate('一、批发业','营业收入'))*100,1));
    else:
        print("error")

    if (getdate('二、零售业','营业收入')> 0  and  getdate('二、零售业','营业成本') > 0):
        print(round((1-getdate('二、零售业','营业成本')/getdate('二、零售业','营业收入'))*100,1));
    else:
        print("error")
    if (getdate_lastyear('二、零售业','营业收入')> 0 and  getdate('二、零售业','营业收入') > 0 and getdate_lastyear('二、零售业','营业成本')> 0 and getdate('二、零售业','营业成本') > 0):





        print(round((getdate_lastyear('二、零售业','营业成本')/getdate_lastyear('二、零售业','营业收入')-getdate('二、零售业','营业成本')/getdate('二、零售业','营业收入'))*100,1));
    else:
        print("error")
    if (   getdate('三、住宿业','营业收入')  > 0 and getdate('三、住宿业','营业收入') > 0) :
        print(round((1-getdate('三、住宿业','营业成本')/getdate('三、住宿业','营业收入'))*100,1));
    else:
        print("error")
    if (getdate_lastyear('三、住宿业','营业收入')> 0  and  getdate('三、住宿业','营业收入') > 0 and getdate_lastyear('三、住宿业','营业成本')>0 and getdate('三、住宿业','营业成本') >  0 ):
        print(round((getdate_lastyear('三、住宿业','营业成本')/getdate_lastyear('三、住宿业','营业收入')-getdate('三、住宿业','营业成本')/getdate('三、住宿业','营业收入'))*100,1));
    else:
        print("error")
    if (   getdate('四、餐饮业','营业收入')  > 0 and getdate('四、餐饮业','营业成本') >0):
        print(round((1-getdate('四、餐饮业','营业成本')/getdate('四、餐饮业','营业收入'))*100,1));
    else:
        print("error")
    if ( getdate_lastyear('四、餐饮业','营业收入')> 0  and  getdate('四、餐饮业','营业收入') > 0 and getdate_lastyear('四、餐饮业','营业成本') > 0 and getdate('四、餐饮业','营业成本') > 0 ):
        print(round((getdate_lastyear('四、餐饮业','营业成本')/getdate_lastyear('四、餐饮业','营业收入')-getdate('四、餐饮业','营业成本')/getdate('四、餐饮业','营业收入'))*100,1));
    else:
        print("error")




    print('营业收入户均值')

    if ( getdate('一、批发业','企业数')> 0):
        print(round(getdate('一、批发业','营业收入')/getdate('一、批发业','企业数')*10000,1));
    else:
        print("error")
    if (   getdate('二、零售业','企业数')  > 0):
        print(round(getdate('二、零售业','营业收入')/getdate('二、零售业','企业数')*10000,1));
    else:
        print("error")
    if ( getdate('三、住宿业','企业数')> 0):
        print(round(getdate('三、住宿业','营业收入')/getdate('三、住宿业','企业数')*10000,1));
    else:
        print("error")
    if (   getdate('四、餐饮业','企业数')  > 0):
        print(round(getdate('四、餐饮业','营业收入')/getdate('四、餐饮业','企业数')*10000,1));
    else:
        print("error")

    print('营业收入人均值')



    if (getdate('一、批发业','从业人员平均人数(人)')> 0):
        print(round(getdate('一、批发业','营业收入')/getdate('一、批发业','从业人员平均人数(人)')*10000,1));
    else:
        print("error")

    if (getdate('二、零售业','从业人员平均人数(人)')> 0):
        print(round(getdate('二、零售业','营业收入')/getdate('二、零售业','从业人员平均人数(人)')*10000,1));
    else:
        print("error")

    if (getdate('三、住宿业','从业人员平均人数(人)')> 0):
        print(round(getdate('三、住宿业','营业收入')/getdate('三、住宿业','从业人员平均人数(人)')*10000,1));
    else:
        print("error")

    if (getdate('四、餐饮业','从业人员平均人数(人)') > 0):
        print(round(getdate('四、餐饮业','营业收入')/getdate('四、餐饮业','从业人员平均人数(人)')*10000,1));
    else:
        print("error")



    print('销售费用')


    print(round(getdate('总计','销售费用'),1));


    print(
      round(  ((getdate('总计','销售费用'))/(getdate_lastyear('总计','销售费用'))- 1)*100,1)
    )

    print(round(getdate('一、批发业','销售费用'),1));
    print(
      round(  ((getdate('一、批发业','销售费用'))/(getdate_lastyear('一、批发业','销售费用'))- 1)*100,1)
    )

    print(round(getdate('二、零售业','销售费用'),1));
    print(
      round(  ((getdate('二、零售业','销售费用'))/(getdate_lastyear('二、零售业','销售费用'))- 1)*100,1)
    )
    print(round(getdate('三、住宿业','销售费用'),1));
    print(
      round(  ((getdate('三、住宿业','销售费用'))/(getdate_lastyear('三、住宿业','销售费用'))- 1)*100,1)
    )

    print(round(getdate('四、餐饮业','销售费用'),1));
    print(
      round(  ((getdate('四、餐饮业','销售费用'))/(getdate_lastyear('四、餐饮业','销售费用'))- 1)*100,1)
    )


    print('管理费用')


    print(round(getdate('总计','管理费用'),1));


    print(
      round(  ((getdate('总计','管理费用'))/(getdate_lastyear('总计','管理费用'))- 1)*100,1)
    )

    print(round(getdate('一、批发业','管理费用'),1));
    print(
      round(  ((getdate('一、批发业','管理费用'))/(getdate_lastyear('一、批发业','管理费用'))- 1)*100,1)
    )

    print(round(getdate('二、零售业','管理费用'),1));
    print(
      round(  ((getdate('二、零售业','管理费用'))/(getdate_lastyear('二、零售业','管理费用'))- 1)*100,1)
    )
    print(round(getdate('三、住宿业','管理费用'),1));
    print(
      round(  ((getdate('三、住宿业','管理费用'))/(getdate_lastyear('三、住宿业','管理费用'))- 1)*100,1)
    )

    print(round(getdate('四、餐饮业','管理费用'),1));
    print(
      round(  ((getdate('四、餐饮业','管理费用'))/(getdate_lastyear('四、餐饮业','管理费用'))- 1)*100,1)
    )



    print('研发费用')


    print(round(getdate('总计','研发费用'),1));


    print(
      round(  ((getdate('总计','研发费用'))/(getdate_lastyear('总计','研发费用'))- 1)*100,1)
    )

    print(round(getdate('一、批发业','研发费用'),1));
    print(
      round(  ((getdate('一、批发业','研发费用'))/(getdate_lastyear('一、批发业','研发费用'))- 1)*100,1)
    )

    print(round(getdate('二、零售业','研发费用'),1));
    print(
      round(  ((getdate('二、零售业','研发费用'))/(getdate_lastyear('二、零售业','研发费用'))- 1)*100,1)
    )
    print(round(getdate('三、住宿业','研发费用'),1));

    if ( getdate_lastyear('三、住宿业','研发费用') != 0):

        print(      round(  ((getdate('三、住宿业','研发费用'))/(getdate_lastyear('三、住宿业','研发费用'))- 1)*100,1)    )
    else:
        print("error")
    print(round(getdate('四、餐饮业','研发费用'),1));

    if ( getdate_lastyear('四、餐饮业','研发费用') != 0):
        print(
      round(  ((getdate('四、餐饮业','研发费用'))/(getdate_lastyear('四、餐饮业','研发费用'))- 1)*100,1)
    )
    else:
        print("error")

        print('财务费用')


    print(round(getdate('总计','财务费用'),1));


    print(
      round(  ((getdate('总计','财务费用'))/(getdate_lastyear('总计','财务费用'))- 1)*100,1)
    )

    print(round(getdate('一、批发业','财务费用'),1));
    print(
      round(  ((getdate('一、批发业','财务费用'))/(getdate_lastyear('一、批发业','财务费用'))- 1)*100,1)
    )

    print(round(getdate('二、零售业','财务费用'),1));
    print(
      round(  ((getdate('二、零售业','财务费用'))/(getdate_lastyear('二、零售业','财务费用'))- 1)*100,1)
    )
    print(round(getdate('三、住宿业','财务费用'),1));
    print(
      round(  ((getdate('三、住宿业','财务费用'))/(getdate_lastyear('三、住宿业','财务费用'))- 1)*100,1)
    )

    print(round(getdate('四、餐饮业','财务费用'),1));
    print(
      round(  ((getdate('四、餐饮业','财务费用'))/(getdate_lastyear('四、餐饮业','财务费用'))- 1)*100,1)
    )

猜你喜欢

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