# 修改了应交增值税 同比下降单位错误的问题 from docx import Document from docx.shared import Inches document = Document() 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 = '12.9诊断 透视图.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: #print(cell.value) if str(str(cell.value).replace(' ', '')).find(date_row) != -1: row_result = cell.row #print(cell.row) #print(cell.column) # print(row_result) else: result = 0 row_result = 0 break for row in ws.iter_rows(): for cell in row: if str(str(cell.value).replace(' ', '')).find(date_column) != -1 and column_resul !=-1: column_result = cell.column # print(column_result) #print(cell.row) #print(cell.column) else: #print(cell.row) #print(cell.column) column_result = -1 break # print(column_result) if row_result == 0 or column_result == -1: result = 0 print(result) 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__': getdate('总计', '槐荫区')