python入门经典视频系列教程(免费,2K超清,送书)

https://study.163.com/course/courseMain.htm?courseId=1006183019&share=2&shareId=400000000398149

# -*- coding: utf-8 -*-
"""
原创作者Toby,qq:231469242
Spyder Editor
excel字段覆盖
参数8个:
两个excel名字
两个sheet名字
4个字段名字
"""
import openpyxl
from openpyxl.cell import get_column_letter,column_index_from_string
#两个excel名字
excel_name1='test.xlsx'
excel_name2='database.xlsx'
#两个表格名字
sheet_name1="Sheet1"
sheet_name2="Sheet1"
wb1=openpyxl.load_workbook(excel_name1)
wb2=openpyxl.load_workbook(excel_name2)
#两个表格名字
sheet=wb1.get_sheet_by_name(sheet_name1)
database=wb2.get_sheet_by_name(sheet_name2) #四个字段参数
#sheet
columnname="C" #共同字段
columnvalue="E" #表格需要更新字段
#database
columnname1="B" #共同字段
columnvalue1="C" #数据库值字段
start=1 sheet_columnvalue_index=column_index_from_string(columnvalue)
sheet_columnvalue_list=sheet.columns[sheet_columnvalue_index-1] sheet_columname_index=column_index_from_string(columnname)
sheet_columnname_list=sheet.columns[sheet_columname_index-1] #根据索引字母,返回列的值,用列表存储
def Column_list(letter,thesheet):
value_list=[]
column_index=column_index_from_string(letter)
cell_list=thesheet.columns[column_index-1]
for cellObj in cell_list[start:]: #console显示不全前面内容,出现第一项不是第一个
#print(cellObj.value)
value_list.append(cellObj.value)
return value_list #数据库的名字和值列表
database_name_list=Column_list(columnname1,database)
database_value_list=Column_list(columnvalue1,database) #合并database名字和值,生成词典
combine_list=zip(database_name_list,database_value_list)
database_dict=dict(combine_list) #sheet的名字和值列表
sheet_name_list=Column_list(columnname,sheet)
sheet_value_list=Column_list(columnvalue,sheet) for i in range(1,len(sheet_columnvalue_list)):
cell=sheet_columnvalue_list[i]
cell1=sheet_columnname_list[i]
#print ("cell:",cell)
#print ("cell1:",cell1)
#如果sheet更新字段的cell值为None,且索引名字在数据库
if cell.value==None and cell1.value in database_name_list:
value=database_dict[cell1.value]
sheet_columnvalue_list[i].value=value #写入查询的值
wb1.save(excel_name1)
wb2.save(excel_name2)

 https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章)

  

excel_vlookup函数_python代码实现的更多相关文章

  1. 编程算法 - 求1+2+...+n(函数指针) 代码(C++)

    求1+2+...+n(函数指针) 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 求1+2+...+n, 要求不能使用乘除法\for\whi ...

  2. 在vs.net 2010,2015 等版本,给JS函数添加代码提示\注释

    经常编写JS的朋友常常会因为函数写多了,隔一段时间就会忘记了函数的用途,或者函数里带的参数作用情况,这个时候会联想到VS工具里的强大提示功能,多希望也能在JS上实现呀,告诉你,这个想法并不是多难,VS ...

  3. python定义的一个简单的shell函数的代码

    把写代码过程中经常用到的一些代码段做个记录,如下代码段是关于python定义的一个简单的shell函数的代码. pipe = subprocess.Popen(cmd, stdout=subproce ...

  4. iOS 使用宏定义函数和代码块

    iOS使用宏定义函数和代码块 今天在开发过程中碰到一个问题:就是父类中要向外发送通知,然后子类中或者其他类中来接收它.当然一般是把它写到类方法中去,但是有个问题,就是如果调用的类不是它的子类,就不能直 ...

  5. 编程算法 - 求1+2+...+n(函数继承) 代码(C++)

    求1+2+...+n(函数继承) 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 求1+2+...+n, 要求不能使用乘除法\for\whi ...

  6. go每个函数写代码例子

    https://github.com/astaxie/gopkg 由于目前golang的手册里面针对函数的例子太少了,很多时候不知道怎么使用,好多人都是看源代码才明白怎么用,这个给我们快速开发gola ...

  7. python中实现延时回调普通函数示例代码

    python中实现延时回调普通函数示例代码 这篇文章主要给大家介绍了关于python中实现延时回调普通函数的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的 ...

  8. Python学习笔记(五)函数和代码复用

    函数能提高应用的模块性,和代码的重复利用率.在很多高级语言中,都可以使用函数实现多种功能.在之前的学习中,相信你已经知道Python提供了许多内建函数,比如print().同样,你也可以自己创建函数, ...

  9. Python基础篇(三)_函数及代码复用

    Python基础篇_函数及代码复用 函数的定义.使用: 函数的定义:通过保留字def实现. 定义形式:def <函数名>(<参数列表>): <函数体> return ...

随机推荐

  1. unittest 运行slenium(一)---创建配置类

    文章主要是创建: log : 日志文件 excel :文档的读写 ini 及 yaml :文件的读取 一:创建log日志文件 主要是对logging框架进行二次封装并输出自己需要的日志格式 1. 首先 ...

  2. Java 反射原理

    一.Java 反射的定义 反射机制是在运行状态中, 对于任意一个类, 都能够知道这个类的所有属性和方法: 对于任意一个对象,都能够调用它的任意一个方法或者属性: 二.反射提供的功能: 在运行时判断任意 ...

  3. Swap Without Extra Variable

    Given two variables, x and y, swap two variables without using a third variable.   Example Given x = ...

  4. Linux命令的详解

           cat /etc/passwd文件中的每个用户都有一个对应的记录行,记录着这个用户的一下基本属性.该文件对所有用户可读.               /etc/shadow  文件正如他 ...

  5. C# 通过 参数返回 C++ 指针

    参数返回 C++ 指针 C++ 代码 Extern_C BASECORELIBRARY_API char * GetFileByteArray(wchar_t * BinfilePath, wchar ...

  6. java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook] with root cause

    一.问题描述 使用POI上传excel,本地可正常运行,开发服务器上报错. 二.异常信息如下: 2019-05-05 17:00:22,349 ERROR [http-nio-8080-exec-7] ...

  7. eslint 对下一行不要校验报错

    eslint 对下一行不要校验报错: <--eslint-disable-next-line--> <div>todo</div> 扩展知识: stylelint ...

  8. 洛谷 P2580 于是他错误的点名开始了 题解

    每日一题 day10 打卡 Analysis trie树模板题,只需用到简单的插入和查询就好了 如果想要学trie树,见信息学奥赛一本通·提高篇P82 #include<iostream> ...

  9. 洛谷 P1309 瑞士轮 题解

    每日一题 day4 打卡 Analysis 暴力+快排(其实是归并排序) 一开始天真的以为sort能过,结果光荣TLE,由于每次只更改相邻的元素,于是善于处理随机数的快排就会浪费很多时间.于是就想到归 ...

  10. 怎样运行jar包中的文件

    1. 2.编辑sysmodule.cmd文件 java -cp sysmodule.jar;classes12.jar;mysql-connector-java-5.0.3-bin.jar;jbcl. ...