首页 > 其他分享 >将Excel数据自动录入国家防返贫系统

将Excel数据自动录入国家防返贫系统

时间:2023-11-19 23:55:26浏览次数:41  
标签:Excel driver dict 返贫 录入 table div getData row

不会编程的看这里:https://www.cnblogs.com/liangxinhy/p/17842931.html

一、配置运行环境

(1)语言python,编程软件Pychram

(2)下载三个功能库——selenium、xlrd、xlwt

import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
import xlrd
import xlwt

selenium新版本大改,很多接口都改了,下低版本,和我版本一致

(3)下载谷歌浏览器,查看浏览器版本(下一个低版本的Chrome)

打开chrome 在网页地址栏中输入 “chrome://version/”来查看chrome版本

(4)下载合适的chromedriver.exe

访问此网站:http://chromedriver.storage.googleapis.com/index.html
然后选择合适版本的chromedriver.exe,版本尽量一致,不一致就选择相似的版本,一般没有问题

(5)将下载的文件解压到D盘下的pip文件夹下面(也可以改代码——driver = getDriver(driverLocation="D:/pip/chromedriver.exe"))

二、复制代码运行

(1)运行前记得改代码

a、getIncomeInfo是获取监测户得收入情况信息,请根据自己的excel修改对应列

def getIncomeInfo(table, row):
    dict = {"户主姓名":"", "公益性岗位收入": "", "其它工资性收入": "", "财产性收入": "最低保证金", "特困人员救助供养金": "",
            "养老或离退休金": "", "计划生育金": "","生态补偿金": "", "产业奖励": "", "就业奖励": "",
            "其它转移性收入": "", "生产经营性收入": "", "专项用于减少生产经营支出的补贴": "","生产经营性支出": ""}
    dict["户主姓名"] = getData(table, row, 3)
    dict["公益性岗位收入"] = getData(table, row, 5)
    dict["其它工资性收入"] = getData(table, row, 6)
    dict["财产性收入"] = getData(table, row, 18)
    dict["最低保证金"] = getData(table, row, 12)
    dict["特困人员救助供养金"] = getData(table, row, 13)
    dict["养老或离退休金"] = getData(table, row, 11)
    dict["计划生育金"] = getData(table, row, 10)
    dict["生态补偿金"] = getData(table, row, 14)
    dict["产业奖励"] = getData(table, row, 15)
    dict["就业奖励"] = getData(table, row, 16)
    dict["其它转移性收入"] = getData(table, row, 17)
    dict["生产经营性收入"] = getData(table, row, 7)
    dict["专项用于减少生产经营支出的补贴"] = getData(table, row, 9)
    dict["生产经营性支出"] = getData(table, row, 8)
    return dict

b、修改excel表的位置和表名(提一句,记得xlrd、xlwt只有控制.xls文件,记得把.xlsx另存为.xls文件)

table = gettable("D:/pip/脱贫户收入录入.xls", "Sheet1")

c、修改excel对应的身份证所在列

id = getData(table, row, 6)

d、修改运行文件所在位置及文件名

savePath = 'D:/pip/运行结果.xls'

(2)代码源码

import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
import xlrd
import xlwt



# 获取driver
def getDriver(driverLocation):
    chromeDriverLocation = driverLocation
    driver = webdriver.Chrome(executable_path=chromeDriverLocation)
    return driver

def refresh(driver):
    driver.refresh()
    print("浏览器刷新")
    WebDriverWait(driver, 90, 2).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="myApplica"]/div/div[1]/div[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="dialog"]/div/center/div/div/ul/li[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/input'))).send_keys(
        "户年度基础信息更新")
    flag = 1
    while True:
        try:
            if flag == 90:
                break
            WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/i'))).click()
            break
        except:
            flag = flag + 1
            time.sleep(0.5)
    if flag == 90:
        raise Exception("出问题了,waitForLogin1")
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH,
                                                                         '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/app-menu/ul/nui-main-menu/div/div/div[2]/div/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/a/span[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="aab004"]')))
    print("刷新成功")


def refresh1(driver):
    driver.refresh()
    print("浏览器刷新")
    WebDriverWait(driver, 90, 2).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="myApplica"]/div/div[1]/div[1]'))).click()
    WebDriverWait(driver, 90, 0.5).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="dialog"]/div/center/div/div/ul/li[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located(
        (By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/input'))).send_keys(
        "户年度基础信息更新")
    flag = 1
    while True:
        try:
            if flag == 90:
                break
            WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located(
                (By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/i'))).click()
            break
        except:
            flag = flag + 1
            time.sleep(0.5)
    if flag == 90:
        raise Exception("出问题了,waitForLogin1")
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH,
                                                                         '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/app-menu/ul/nui-main-menu/div/div/div[2]/div/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/a/span[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="aab004"]')))
    print("重新登录成功")



# 登录页面,进入监测户信息界面
def waitForLogin(driver):
    driver.get("http://106.38.235.201:7080/cas/login")
    driver.maximize_window()
    WebDriverWait(driver, 300, 2).until(EC.presence_of_element_located((By.XPATH, '//*[@id="myApplica"]/div/div[1]/div[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="dialog"]/div/center/div/div/ul/li[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/input'))).send_keys("户年度基础信息更新")
    flag = 1
    while True:
        try:
            if flag == 90:
                break
            WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/i'))).click()
            break
        except:
            flag = flag + 1
            time.sleep(0.5)
    if flag == 90:
        raise Exception("出问题了,waitForLogin")
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/app-menu/ul/nui-main-menu/div/div/div[2]/div/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/a/span[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="aab004"]')))
    print("登录成功")

# 登录页面,进入脱贫户信息界面
def waitForLogin1(driver):
    driver.get("http://106.38.235.201:7080/cas/login")
    driver.maximize_window()
    WebDriverWait(driver, 300, 2).until(EC.presence_of_element_located((By.XPATH, '//*[@id="myApplica"]/div/div[1]/div[1]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="dialog"]/div/center/div/div/ul/li[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/input'))).send_keys("户年度基础信息更新")
    flag = 1
    while True:
        try:
            if flag == 90:
                break
            WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/div[2]/i'))).click()
            break
        except:
            flag = flag + 1
            time.sleep(0.5)
    if flag == 90:
        raise Exception("出问题了,waitForLogin1")
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH, '/html/body/app-root/div/div/app-main-layout/div/div[1]/div/div/app-menu/ul/nui-main-menu/div/div/div[2]/div/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/nui-main-menu-sub/ul/li/a/span[2]'))).click()
    WebDriverWait(driver, 90, 0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="aab004"]')))
    print("登录成功")

# 等待元素加载,并点击(通过 XPATH 获取元素)


# def waitEle(driver, XPATH):
#     WebDriverWait(driver, 30, 0.5).until(EC.presence_of_element_located((By.XPATH, XPATH)))

def clickEle(driver, XPATH):
    WebDriverWait(driver, 60, 0.5).until(EC.presence_of_element_located((By.XPATH, XPATH))).click()

def sendInf0(driver, XPATH, info):
    WebDriverWait(driver, 60, 0.5).until(EC.presence_of_element_located(
        (By.XPATH, XPATH))).clear()
    WebDriverWait(driver, 60, 0.5).until(EC.presence_of_element_located(
        (By.XPATH, XPATH))).send_keys(info)

#输入身份证,打开监测户收入计算界面

def findPerson(id):
    #输入id
    #点击搜索
    flag = 0
    while True:
        try:
            if flag == 10:
                break
            sendInf0(driver, '//*[@id="aab004"]', id)
            clickEle(driver, '//*[@id="on_query"]/span')
            break
        except:
            # print("bug")
            flag = flag + 1
            time.sleep(0.5)
    if flag == 10:
        raise Exception("出问题了,点不了搜索身份证")

    # mark = 0
    # while True:
    # try:
    #     th = driver.find_element(By.XPATH, '//*[@id="ui-tabpanel-4"]/div/busi-tab/object-poor-family/p-panel[3]/div/div[2]/div/div/object-poor-family-grid/p-datatable/div/div[1]/div/div[2]/div/table/tbody/tr')
    #     tds = th.find_elements(By.TAG_NAME, 'td')
    #     print(len(tds))
    #     xinxi = tds[0].text.strip()
    #     print(xinxi)
    # except Exception as e:
    #     print(str(e))
    # print(driver.find_element(
    #         '//*[@id="ui-tabpanel-2"]/div/busi-tab/object-poor-family/p-panel[3]/div/div[2]/div/div/object-poor-family-grid/p-datatable/div/nui-paginator/div/div/div[3]/label/span').text.strip())
        # if driver.find_element(
        #         '//*[@id="ui-tabpanel-2"]/div/busi-tab/object-poor-family/p-panel[3]/div/div[2]/div/div/object-poor-family-grid/p-datatable/div/nui-paginator/div/div/div[3]/label/span').text.strip() != "总户数:0 总人数:0":
        #     break
        # if driver.find_element(
        #         '//*[@id="ui-tabpanel-2"]/div/busi-tab/object-poor-family/p-panel[3]/div/div[2]/div/div/object-poor-family-grid/p-datatable/div/nui-paginator/div/div/div[3]/label/span').text.strip() == "总户数:0 总人数:0":
        #     time.sleep(0.5)
        #     mark == mark + 1
        # if mark == 60:
        #     raise Exception("身份证搜不到")


    # flag1 = 0
    # while True:
    # #     try:
    #         if flag1 == 10:
    #             break
def incomeCalculationPage(id):
    # 点击姓名超链接,进入监测户信息界面
    flag = 0
    while True:
        try:
            # print("尝试")
            if flag == 3:
                # print("用身份证搜不到人")
                break
            clickEle(driver,
                 '//*[@id="ui-tabpanel-1"]/div/busi-tab/object-poor-family/p-panel[3]/div/div[2]/div/div/object-poor-family-grid/p-datatable/div/div[1]/div/div[2]/div/table/tbody/tr/td[4]/span/span')
            clickEle(driver,
                     '//*[@id="ui-tabpanel-1"]/div/busi-tab/object-poor-family/p-dialog[1]/div/div[2]/p-tabview/div/ul/li[3]/a')
            break
        except:
            time.sleep(1)
            flag = flag + 1
            # print(flag)
    if flag == 3:
        # print("抛出异常")
        raise Exception("找不到人")
            # waitEle(driver, '//*[@id="aac073_3"]')
            # break
        # except:
        #     # print("bug2")
        #     time.sleep(0.5)
        #     flag1 = flag1 + 1
    # if flag1 == 10:
    #     raise Exception("没有进入算收入页面")





# #获取监测户得收入情况信息(良安、童家)
# def getIncomeInfo(table, row):
#     dict = {"户主姓名":"", "公益性岗位收入": "", "其它工资性收入": "", "财产性收入": "最低保证金", "特困人员救助供养金": "",
#             "养老或离退休金": "", "计划生育金": "","生态补偿金": "", "产业奖励": "", "就业奖励": "",
#             "其它转移性收入": "", "生产经营性收入": "", "专项用于减少生产经营支出的补贴": "","生产经营性支出": ""}
#     dict["户主姓名"] = getData(table, row, 3)
#     dict["公益性岗位收入"] = getData(table, row, 5)
#     dict["其它工资性收入"] = getData(table, row, 6)
#     dict["财产性收入"] = getData(table, row, 18)
#     dict["最低保证金"] = getData(table, row, 12)
#     dict["特困人员救助供养金"] = getData(table, row, 13)
#     dict["养老或离退休金"] = getData(table, row, 11)
#     dict["计划生育金"] = getData(table, row, 10)
#     dict["生态补偿金"] = getData(table, row, 14)
#     dict["产业奖励"] = getData(table, row, 15)
#     dict["就业奖励"] = getData(table, row, 16)
#     dict["其它转移性收入"] = getData(table, row, 17)
#     dict["生产经营性收入"] = getData(table, row, 7)
#     dict["专项用于减少生产经营支出的补贴"] = getData(table, row, 9)
#     dict["生产经营性支出"] = getData(table, row, 8)
#     return dict


#佛星
def getIncomeInfo(table, row):
    dict = {"户主姓名":"", "公益性岗位收入": "", "其它工资性收入": "", "财产性收入": "最低保证金", "特困人员救助供养金": "",
            "养老或离退休金": "", "计划生育金": "","生态补偿金": "", "产业奖励": "", "就业奖励": "",
            "其它转移性收入": "", "生产经营性收入": "", "专项用于减少生产经营支出的补贴": "","生产经营性支出": ""}
    dict["户主姓名"] = getData(table, row, 5)
    dict["公益性岗位收入"] = getData(table, row, 9)
    dict["其它工资性收入"] = getData(table, row, 10)
    dict["财产性收入"] = getData(table, row, 11)
    dict["最低保证金"] = getData(table, row, 13)
    dict["特困人员救助供养金"] = getData(table, row, 14)
    dict["养老或离退休金"] = getData(table, row, 15)
    dict["计划生育金"] = getData(table, row, 16)
    dict["生态补偿金"] = getData(table, row, 17)
    dict["产业奖励"] = getData(table, row, 18)
    dict["就业奖励"] = getData(table, row, 19)
    dict["其它转移性收入"] = getData(table, row, 20)
    dict["生产经营性收入"] = getData(table, row, 21)
    dict["专项用于减少生产经营支出的补贴"] = getData(table, row, 24)
    dict["生产经营性支出"] = getData(table, row, 23)
    return dict

#蟠龙
# def getIncomeInfo(table, row):
#     dict = {"户主姓名":"", "公益性岗位收入": "", "其它工资性收入": "", "财产性收入": "最低保证金", "特困人员救助供养金": "",
#             "养老或离退休金": "", "计划生育金": "","生态补偿金": "", "产业奖励": "", "就业奖励": "",
#             "其它转移性收入": "", "生产经营性收入": "", "专项用于减少生产经营支出的补贴": "","生产经营性支出": ""}
#     dict["户主姓名"] = getData(table, row, 3)
#     dict["公益性岗位收入"] = getData(table, row, 8)
#     dict["其它工资性收入"] = getData(table, row, 9)
#     dict["财产性收入"] = getData(table, row, 21)
#     dict["最低保证金"] = getData(table, row, 13)
#     dict["特困人员救助供养金"] = getData(table, row, 14)
#     dict["养老或离退休金"] = getData(table, row, 15)
#     dict["计划生育金"] = getData(table, row, 16)
#     dict["生态补偿金"] = getData(table, row, 17)
#     dict["产业奖励"] = getData(table, row, 18)
#     dict["就业奖励"] = getData(table, row, 19)
#     dict["其它转移性收入"] = getData(table, row, 20)
#     dict["生产经营性收入"] = getData(table, row, 10)
#     dict["专项用于减少生产经营支出的补贴"] = 0
#     dict["生产经营性支出"] = getData(table, row, 11)
#     return dict




#填写监测户得收入情况信息
def setIncomeInformation(driver, dict):
    message = []
    #获取需填入收入
    #1、公益性岗位收入
    sendInf0(driver, '//*[@id="aac355_3"]', dict["公益性岗位收入"])
    #2、其它工资性收入
    sendInf0(driver, '//*[@id="aac356_3"]', dict["其它工资性收入"])
    #3、财产性收入
    sendInf0(driver, '//*[@id="aac072_3"]', dict["财产性收入"])
    #4、最低保证金
    sendInf0(driver, '//*[@id="aac077_3"]', dict["最低保证金"])
    #5、特困人员救助供养金
    sendInf0(driver, '//*[@id="aac086_3"]', dict["特困人员救助供养金"])
    #6、养老或离退休金
    sendInf0(driver, '//*[@id="aac087_3"]', dict["养老或离退休金"])
    #7、计划生育金
    sendInf0(driver, '//*[@id="aac076_3"]', dict["计划生育金"])
    #8、生态补偿金
    sendInf0(driver, '//*[@id="aac078_3"]', dict["生态补偿金"])
    #9、产业奖励
    sendInf0(driver, '//*[@id="aac357_3"]', dict["产业奖励"])
    #10、就业奖励
    sendInf0(driver, '//*[@id="aac358_3"]', dict["就业奖励"])
    #11、其它转移性收入
    sendInf0(driver, '//*[@id="aac083_3"]', dict["其它转移性收入"])
    #12、生产经营性收入
    sendInf0(driver, '//*[@id="aac071_3"]', dict["生产经营性收入"])
    #13、专项用于减少生产经营支出的补贴
    sendInf0(driver, '//*[@id="aac360_3"]', dict["专项用于减少生产经营支出的补贴"])
    #14、生产经营性支出
    sendInf0(driver, '//*[@id="aac359_3"]', dict["生产经营性支出"])


    clickEle(driver, '//*[@id="on_save"]/span')
    clickEle(driver, '//*[@id="swal2-content"]')
    cw = driver.find_element(By.XPATH, '//*[@id="swal2-content"]')
    cwtext = cw.text
    message.append(dict["户主姓名"])
    message.append(cwtext)
    # if len(cwtext) < 4:
    #     print("bug文本信息" + cwtext)
    if cwtext == "保存成功":
        clickEle(driver, '/html/body/div[70]/div/div[10]/button[1]')
        clickEle(driver, '//*[@id="ui-tabpanel-1"]/div/busi-tab/object-poor-family/p-dialog[1]/div/div[1]/a/span')
        print(dict["户主姓名"] + cwtext)
        message.append(1)
    else:
        try:
            clickEle(driver, '/html/body/div[70]/div/div[10]/button[2]')
            clickEle(driver, '//*[@id="ui-tabpanel-1"]/div/busi-tab/object-poor-family/p-dialog[1]/div/div[1]/a/span')
            message.append(2)
            print(dict["户主姓名"] + "未录入收入,有严重提醒:" + cwtext)
        except:
            clickEle(driver, '/html/body/div[70]/div/div[10]/button[1]')
            clickEle(driver, '//*[@id="ui-tabpanel-1"]/div/busi-tab/object-poor-family/p-dialog[1]/div/div[1]/a/span')
            if "大于等于0且小数在两位之内" in cwtext:
                message.append(2)
                print(dict["户主姓名"] + "未录入收入,有提醒:" + cwtext)
            message.append(3)
            print(dict["户主姓名"] + "已录入收入,提示信息:" + cwtext)
    return message


def gettable(address, tableName):
    excel = xlrd.open_workbook(address)
    table = excel.sheet_by_name(tableName)
    return table

def getData(table, row, col):
    return table.cell_value(row - 1, col - 1)



if __name__ == '__main__':
    try:
        start_time = time.time()
        cgmessage = []
        cwmessage = []
        txmessage = []
        #(一)获取录入信息表
        table = gettable("C:/Users/liangxin/Desktop/fx.xls", "总表")
        #(二)获取driver
        driver = getDriver(driverLocation="D:/pip/chromedriver.exe")
        #(三)登录页面
        waitForLogin1(driver)
        # (四)进行信息录入
        # print(table.nrows + 1)
        num = 0
        for row in range(2, table.nrows + 1):
            # row = 2
            id = getData(table, row, 6)
            dict = getIncomeInfo(table, row)
            flag = 1
            while True:
                try:
                    if flag == 10:
                        break
                    findPerson(id)
                    try:
                        incomeCalculationPage(id)
                    except:
                        messa = []
                        messa.append(dict["户主姓名"])
                        messa.append("用身份证不到这个人,可能被删了")
                        messa.append(2)
                        messa.append(id)
                        cwmessage.append(messa)
                        break
                    mes = setIncomeInformation(driver, dict)
                    if mes[2] == 1:
                        mes.append(id)
                        cgmessage.append(mes)
                    elif mes[2] == 2:
                        mes.append(id)
                        cwmessage.append(mes)
                    elif mes[2] == 3:
                        mes.append(id)
                        txmessage.append(mes)
                    break
                except:
                    refresh1(driver)
                    flag += 1
            if flag == 10:
                print("已经刷新10次了,换个时间录入吧")
                break
            num = num + 1
    except:
        print("异常结束")
    finally:
        driver.quit()
        finish_time = time.time()
        during_time = finish_time - start_time
        # print("共录入" + str(num - len(cwmessage)) + "条数据")
        # print("程序共运行" + str((during_time - during_time % 60) / 60) + "分钟" + str(during_time % 60)[2] + "秒")
        # print("=========================成功录入的人员信息============================")
        # for cg in cgmessage:
        #     print(cg[0] + "(" + cg[3] + ")" + ":" + cg[1])
        # print("=========================错误信息====================================")
        # for cw in cwmessage:
        #     print(cw[0] + "(" + cw[3] + ")" + ":" + cw[1])
        # print("==========================提醒信息====================================")
        # for tx in txmessage:
        #     print(tx[0] + "(" + tx[3] + ")" + ":" + tx[1])


        # 生成运行结果excel
        workbook = xlwt.Workbook(encoding='utf-8')
        sheet0 = workbook.add_sheet("运行结果")
        sheet0.write(0, 0, "成功共录入" + str(len(cgmessage)) + "条数据")
        sheet0.write(1, 0, "未录入" + str(len(cwmessage)) + "条数据")
        sheet0.write(2, 0, "提示消息" + str(len(txmessage)) + "条数据,需要根据提示自己判断有没有录入")
        sheet0.write(3, 0, "程序共运行" + str((during_time - during_time % 60) / 60) + "分钟" + str(during_time % 60)[2] + "秒")
        sheet0.write(4, 0, "共尝试录入" + str(num) + "条数据")
        sheet0.write(4, 0, "从第2行开始录入,一直到" + str(2 + num) + "行结束运行")



        head = ["姓名", "点击保存后显示的信息", "分类", "身份证号"]

        # 录入成功人员
        sheet1 = workbook.add_sheet("成功录入收入人员")
        for i in head:
            sheet1.write(0, head.index(i), i)
        for i in range(len(cgmessage)):
            for j in range(len(cgmessage[i])):
                sheet1.write(i + 1, j, cgmessage[i][j])

        # 录入没有成功人员
        sheet2 = workbook.add_sheet("没有录入收入人员")
        for i in head:
            sheet2.write(0, head.index(i), i)
        for i in range(len(cwmessage)):
            for j in range(len(cwmessage[i])):
                sheet2.write(i + 1, j, cwmessage[i][j])

        # 录入提示信息
        sheet3 = workbook.add_sheet("提示信息")
        for i in head:
            sheet3.write(0, head.index(i), i)
        for i in range(len(txmessage)):
            for j in range(len(txmessage[i])):
                sheet3.write(i + 1, j, txmessage[i][j])

        savePath = 'D:/pip/哇,鑫哥强呀.xls'
        workbook.save(savePath)



标签:Excel,driver,dict,返贫,录入,table,div,getData,row
From: https://www.cnblogs.com/liangxinhy/p/17812226.html

相关文章

  • Python批量求取Excel表格每一个4行内某列的最大值、最小值
      本文介绍基于Python语言,基于Excel表格文件内某一列的数据,计算这一列数据在每一个指定数量的行的范围内(例如每一个4行的范围内)的区间最大值的方法。  已知我们现有一个.csv格式的Excel表格文件,其中有一列数据,我们希望对其加以区间最大值的计算——即从这一列的数据部分(也就是......
  • Spring Boot 如何获取Excel sheet页的数量?
    前言在日常的开发中,我们经常需要读取Excel文件中的数据,其中涉及到获取Excel中sheet页的数量。本文将介绍如何使用SpringBoot获取Excelsheet页的数量。摘要本文主要介绍了如何使用SpringBoot获取Excel文件中sheet页的数量。首先通过POI库读取Excel文件,然后通过Workbook对象获......
  • PageOfficeV6.0在线打开excel文件给单元格填充数据
    转载:单元格填充数据单元格填充数据注意本文中展示的代码均为关键代码,复制粘贴到您的项目中,按照实际的情况,例如文档路径,用户名等做适当修改即可使用。PageOffice提供了Workbook对象来实现对Excel文件的数据填充功能,如果只是简单的填充一下数据,那么通过调用Sheet对象的openCell......
  • (08)类似Excel数据透视表功能的DBCross1
    其他参考(09)打印StringGrid第3步 如对name分组计数 ......
  • JAVA解析Excel文件 + 多线程 + 事务回滚
    1.项目背景:客户插入Excel文件,Ececel文件中包含大量的数据行和数据列,单线程按行读取,耗时大约半小时,体验感不好。思路:先将excel文件按行读取,存入List,然后按照100均分,n=list.szie()/100+1;n就是要开启的线程总数。(实际使用的时候,数据库连接池的数量有限制,n的大小要结合数据库连......
  • JAVA 解析Excel + 多线程 + 事务回滚(2)
    该方法为网上查询,感觉可行,并未真正尝试。主线程:packagecom.swagger.demo.service;importcom.alibaba.excel.context.AnalysisContext;importcom.alibaba.excel.event.AnalysisEventListener;importcom.swagger.demo.config.SpringJobBeanFactory;importcom.swagger.demo.m......
  • 35个超实用excel快捷键
    以下是一些常用的Excel快捷键,希望对你有所帮助。如果你想要了解更多快捷键,可以参考Excel的官方文档或者在网上搜索相关信息。Ctrl+C:复制选定的单元格或单元格范围。Ctrl+X:剪切选定的单元格或单元格范围。Ctrl+V:粘贴复制或剪切的内容。Ctrl+Z:撤销上一步操作。Ctrl+......
  • CSV文件中含有逗号和双引号的文本如何在Excel中正确的显示
    在工作中将文本保存为CSV格式遇到过一个问题,当文本中含有逗号和双引号的时候,用Excel打开这个文件,文本的内容显示会出现问题。当文本含有逗号时,Excel打开csv文件会默认逗号为分隔符,将一个文本分割成几个单位格显示。如下图: 图1.记事本打开是正常的   图2.Excel中打开后文......
  • 软件分类——博客园标签分类以及“博客网页编辑博客,如何插入Excel中的表格,并且可在网
    .NET技术:后端开发:软件设计:前端开发:企业信息化:移动端开发:软件工程:数据库:操作系统:其他分类:.NET新手区Java架构设计Html/CssBPMAndroid开发敏捷开发SQLServerWindows非技术区ASP.NETPython面向对象JavaScriptSharePointiOS开发项目与团队管理Orac......
  • 考试题库通过excel导入试题
    ps:最近在做的考试试题导入,留个痕本人有点菜,实现方式有些简单,各位有什么优化也可以拿去改,0.0;这个方法可以获取对象试题字段的字段值和字段名并且可以根据字段上的注解判断字段是否要处理有类似的业务还是可以用用的一.demo测试代码:publicstaticvoidmain(String[]ar......