首页 > 其他分享 >哈哈哈

哈哈哈

时间:2023-08-09 10:24:26浏览次数:27  
标签:sheet num print obj 哈哈哈 col row

import xlrd

excelFileName = "/Users/toby/Desktop/Python/testFile.xls"
sql1Name = "sql1.sql"
sql2Name = "sql2.sql"

readfile = xlrd.open_workbook(excelFileName)
# print(readfile)

sheetNamesList = readfile.sheet_names()
# print(sheetNamesList)

# 获取sheet对象
obj_sheet = readfile.sheet_by_name(sheetNamesList[0])
# print(obj_sheet)

# 获取sheet行数
row = obj_sheet.nrows
# 获取sheet列数
col = obj_sheet.ncols
# print("row:", row)
# print("col:", col)

# 获取 数据
f1 = open(sql1Name, "w")
f2 = open(sql2Name, "w")

for row_num in range(2, row):
    col_num = 2
    while(col_num < col - 1):
        url = obj_sheet.cell_value(row_num, col_num)

        if(url.startswith("http") or url == ""):
            continue

        col_num += 1
        method_code = obj_sheet.cell_value(row_num, col_num)
        sql1 = "update sys set url = \'" + url + "\' where method_code = \'" + str(method_code) + "\'; \n"
        f1.write(sql1)
        sql2 = "update sys set url = null" + " where method_code = \'" + str(method_code) + "\'; \n"
        f2.write(sql2)
        print(sql1, sql2)
f1.close()
f2.close()

标签:sheet,num,print,obj,哈哈哈,col,row
From: https://www.cnblogs.com/kunande/p/17616164.html

相关文章