• UIBOT加python实现从excel中提取n行数据存入新的excel并命名


    1. 需求是实现从excel中提取n行数据存入新的excel并命名,要求不能乱码,以下是完整的uibot代码
    Import HuangkaSixtyfive
    Import ReNames
    Dim objRet ,objRet1,objRet2= ""
    Dim arrSet = ""
    Dim arrayRet = ""
    Dim objExcelWorkBook = ""
    
    
    
    objExcelWorkBook = Excel.OpenExcel('''E:\老人卡\20220506订单数据.xlsx''',False,"Excel","","")
    Dim rownum = 1202   //1202代表的是第1202行
    
    arrayRet = Excel.ReadRange(objExcelWorkBook,"65周岁敬老卡","A"&rownum&":K"&rownum+99)
    Dim objRet0,objRetk=""
    objRet0 = Excel.ReadCell(objExcelWorkBook,"65周岁敬老卡","B"&rownum)
    objRetk = Excel.ReadCell(objExcelWorkBook,"65周岁敬老卡","B"&rownum+99)
    TracePrint("所读序列是:"&objRet0&"-"&objRetk)
    
    Excel.CloseExcel(objExcelWorkBook,True)
    
    
    HuangkaSixtyfive.print_hi('Linlili~~~~~')//python 新建XXXXX操作员.xlsx'python 代码
    //保存到新的excel
    objExcelWorkBook = Excel.OpenExcel('''E:\老人卡\XXXXX操作员.xlsx''',False,"Excel","","")
    //yearoldTrans.print_hi("world")
    
    Excel.WriteRange(objExcelWorkBook,"Sheet1","A2:K101",arrayRet,False)
    objRet = Excel.ReadCell(objExcelWorkBook,"Sheet1","B2")
    Excel.WriteRange(objExcelWorkBook,"Sheet1","A2:K101",arrayRet,True)
    objRet1 = Excel.ReadCell(objExcelWorkBook,"Sheet1","B2")
    Dim B1
    B1 = CStr(objRet1)
    //Excel.WriteCell(objExcelWorkBook,"Sheet1","B1","'"&B1,True)
    
    
    objRet2 = Excel.ReadCell(objExcelWorkBook,"Sheet1","B101") //读取最后一行的序列
    Dim B2
    B2 = CStr(objRet2)
    Excel.WriteCell(objExcelWorkBook,"Sheet1","C1",B1&"-"&B2,True)
    
    
    Excel.CloseExcel(objExcelWorkBook,True)
    ReNames.rename()//重命名文件python
    CollectGarbage
    1. python代码在自己的目录下放置python代码然后xxxxx.lib下放置的是内库

     renames.py

    import pandas as pd
    import os
    
    
    #重命名
    def rename():
        # 读取表格,使用openpyxl引擎,获取表名为表1的内容
        df = pd.read_excel("E:\老人卡\XXXXX操作员.xlsx", engine="openpyxl", sheet_name="Sheet1",header=None)
    
        #df.drop(columns='A',axis=1)
        # 读取指定单元格,读取第一行,第一列,即A2单元格(pandas读取表格默认不读取表头,即第一行)
        one_cell = df.iat[0, 2]
        print(one_cell)
        os.rename("E:\老人卡\XXXXX操作员.xlsx","E:\老人卡\{}--------------------------.xlsx".format(one_cell))
    
    if __name__ == '__main__':
        rename()

    replaces.py

    # -*- coding: utf-8 -*-
    import os
    import shutil
    
    
    def listdir(path, list_name):  # 传入存储的list
        for file in os.listdir(path):
            file_path = os.path.join(path, file)
            if os.path.isdir(file_path):
                listdir(file_path, list_name)
            else:
                list_name.append((file_path, os.path.getctime(file_path)))
    
    
    def newestfile(target_list):
        newest_file = target_list[0]
        for i in range(len(target_list)):
            if i < (len(target_list) - 1) and newest_file[1] < target_list[i + 1][1]:
                newest_file = target_list[i + 1]
            else:
                continue
        print('newest file is', newest_file)
        return newest_file
    
    def set(k):
        default_path = r'C:\Users\Asus\Downloads'
        down_file = r'C:\Users\Asus\Desktop\ie客户平台数据对比\网上充值明细.xlsx'
        list = []  #暂估价项目疑问-3.31.xls
        listdir(default_path, list)
        new_file = newestfile(list)
        print('from:', new_file[0])
        print('to:', shutil.copy(new_file[0], down_file))
        print(k)
    
    
    if __name__ == '__main__':
        set("das")
  • 相关阅读:
    MySQL锁之三:MySQL的共享锁与排它锁编码演示
    服务链路追踪(Spring Cloud Sleuth)
    服务网关zuul之四:zuul网关配置
    hdu 1505 City Game (hdu1506加强版)
    PHP设计模式——訪问者模式
    极客互联网电视不是噱头,用户体验成创维G7200核心竞争力
    深入理解JavaScript系列(23):JavaScript与DOM(上)——也适用于新手
    使用php分页类实现简单分类
    管理之路(四)
    poj 2485 Highways (最小生成树)
  • 原文地址:https://www.cnblogs.com/springcloud/p/16242224.html
Copyright © 2020-2023  润新知