python - '>' 在 'str' 和 'int' 的实例之间不支持我在 excel 中写入时出错
问题描述
import openpyxl
import getpass
import os
import shutil
import sys
from openpyxl.utils import get_column_letter
from openpyxl.styles import Border, Side, NamedStyle, Color, PatternFill, Font, Alignment
from openpyxl.styles import colors
from openpyxl import Workbook
import win32com.client as win32
import xlwings as xw
REMOVE: All counters that are no longer being used. Check on raw_input, row deletion, and pandas.
curr_row = 2
detections = 0
detections_rem_tmfrm = 0
pias_needed = 0
pias_comp = 0
web_num = "Null"
int_end_analysis = 0
int_ptch_analysis = 0
print(e)
op = input('\nDo you want to continue? Y/N\n\n').upper()
if op != "Y":
sys.exit("\nExiting program.")
else:
print("\nContinuing process.")
#get user name
dirpath = os.getcwd()
print("current directory is : " + dirpath)
foldername = os.path.basename(dirpath)
print("Directory name is : " + foldername)
#get current directory
#os.chdir(foldername % username)
#os.path.join(foldername,username)
#Loads Excel sheet with all of the companies' responses recorded.
data_file = openpyxl.load_workbook('_Dash_Da.xlsx')
for row in range (2, q1_sheet.max_row+1):
获取 A 列中单元格的值,行 [无论变量“行”当前表示的 int 值是什么] curr_opco = q1_sheet['B' + str(row)].value
shutil.copy("_Dash_tem.xlsx", "%s Dash.xlsx" % curr_opco)
print("\nCreated Oco Dash Tem")
col_num_left = 6
col_num_right = 13
对于 Quarters_arr 中的季度:
#Keep a placeholder number for the column where this all gets written.
#This will deprecate through the loop
print("\n.......Beginning work on %s...\n" % quarter)
#Iterate through each Op
for row in range (2, 20):
print("Current Op: " + curr_op)
#Gets value of cell in Column A, Row[whatever int the variable "row" is currently representing]
curr_op = quarter['B' + str(row)].value
#print(quarter)
#print(curr_op)
qtr_title = quarter.title
#Load current Op's template file
dashboard = openpyxl.load_workbook('%s Das.xlsx' % curr_op)
exec_summary = dashboard.worksheets[0]
endpt_details = dashboard.worksheets[1]
patching_details = dashboard.worksheets[2]
privacy_details = dashboard.worksheets[3]
cloudmon_details = dashboard.worksheets[4]
critasset_details = dashboard.worksheets[5]
#Add any new worksheet up here
#Collect End sey de
ser_sc_A = quarter['E' + str(row)].value
cl_sc_A = quarter['F' + str(row)].value
dev_A_co = quarter['G' + str(row)].value
ser_sc_S = quarter['I' + str(row)].value
c_s_S = quarter['J' + str(row)].value
ds_S_in = quarter['K' + str(row)].value
在这行代码中我得到错误('>'在'str'和'int'的实例之间不支持)我正在尝试进行一些计算并将其写入excel文件但在这里我得到错误
AVd = (quarter['E' + str(row)].value +quarter['F' + str(row)].value)
if AVd > 0:
AVvalue = (dev_A_co/ AVd)*100
elif AVd==0:
AVvalue = 100
#Get current column letters:
left_col_ltr = (get_column_letter(co
l_num_left))
right_col_ltr = (get_column_letter(col_num_right))
dashboard.save('%s Dash.xlsx' % curr_op)
解决方案
AV 未定义,它正在 if 循环中使用。打印变量和类型的输出以进一步检查。
推荐阅读
- python - 如何将 Keras CNN 模型部署到 Web 服务?
- macos - launchctl config 用户路径有什么作用?
- symfony - Symfony 依赖注入
- java - 这个向上转换的演示如何工作?
- matlab - 如何将键值对添加到 Containers.Map 对象?
- android - 如何为 android 和 ios 单反应原生 kontaktio
- android - 用户和当前进程都没有 android.permission.USE_FINGERPRINT
- perl - Perl - 如何跳过先前处理中已经读取的行
- abap - 如何以编程方式添加表数据以传输请求?
- python - 获取当前选中的 QTreeWidget 单元格