python将多个excel合并

同一个excel文件,分配到各组填写, 最后统一汇总成一个文档反馈。 环境 windows10 python3.7 + openpyxl 目标 in目录存放各个组填写的文档 out目录存放合并后的结果文件 实现 表格 序号 产品 信息 反馈1 反馈2 01 产品1 X 00000 999999 02 产品2 X 11111 888888 03 产品3 X 22222 777777 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 from openpyxl import load_workbook from openpyxl import Workbook import os ## 获取所有的文件 def getfilelist(dirname): li = [] for f in os.listdir(dirname): if f.endswith('.xlsx'): li.append(f) return li ## 更新 ## 1. 打开输出文件,处理一个sheet页面, ## 2. 循环获取某一行记录,放入字典结构从所有的输入文件中获取补充记录 ## 3. 如果是单条直接更新, 如果出现重复记录入职(暂不处理) ## 4. 依据以上处理方式,处理完所有sheet页面 INPATH=".\\in\\" OUTPATH=".\\out\\" productlist = ('product1','product2') ## 1. sheetname名称 ## 2. 位置1: 过滤条件 product 所在列位置,判断是否productlist ## 3. 位置2:通过判断第一个需要填写项判断是否填写数据 sheetlist = ( ('sheet1)', 6, 15), ('sheet2', 6, 13), ('sheet3', 5, 12), ('sheet4', 6, 14)) def update(): inlist = getfilelist(".\\in") outlist = getfilelist(".\\out") for li in sheetlist: sheetname = li[0] product = li[1] firstfilled= li[2] d = readdata(inlist, sheetname, product, firstfilled) writedata(outlist, d, sheetname) def readdata(inlist, sheetname, product, firstfilled): d = {} for i in inlist: wb = load_workbook(filename = INPATH+i) ws = wb[sheetname] row = tuple(ws.rows) c = filter(lambda cell: (cell[product].value in productlist) and (cell[firstfilled].value is not None), row) for cell in c: d[cell[0].row] = cell return d def writedata(outlist, d, sheetname): wbout = load_workbook(filename = OUTPATH+outlist[0]) wsout = wbout[sheetname] print(sheetname) #for key in d.keys(): for key in d: for col in range(1, wsout.max_column+1): wsout.cell(row=key, column=col).value = d[key][col-1].value wbout.save(filename = OUTPATH+outlist[0]) update() 代码调整: ...

2021-02-03 · 2 min · 302 words · Garlic Space

LeetCode- Add and Search Word - Data structure design Solution

leetcode 211 Trie的添加及搜索

2021-01-27 · 5 min · 1015 words · Garlic Space

python map & filter & reduce

map, filter, reduce 是函数式编程的函数, 不再需要循环分支使得代码更加简洁。map/reduce 和google的map/reduce功能是类似的, filter有些类似shuffle, 当然shuffle更多的工作是将相同的key放到同一个reduce计算中 map 1 map(function_to_apply, list_of_inputs) 例如: 1 2 3 4 5 items = [1,2,3,4,5] squared = [] for i in items: squared.append(i**2) print(squared) <=> 等价于 1 2 3 items = [1,2,3,4,5] squared = list(map(lambda x: x**2, items)) print(squared) filter 1 filter(function_to_apply, list_of_inputs) 接着上面的代码继续 1 2 3 4 5 less_than_ten=[] for i in squared: if i < 10: less_than_ten.append(i) print(less_than_ten) <=> 等价于 1 2 3 less_than_ten=[] less_than_ten = list(filter(lambda x: x<10, squared)) print(less_than_ten) reduce 1 reduce(function_to_apply, list_of_inputs) 和上面两个函数不同, reduce将进行迭代合并操作 1 2 3 4 product = 0 for i in less_than_ten: product = product + i print(product) <=> 等价于 ...

2021-01-17 · 1 min · 129 words · Garlic Space

可逆计算 reversible computing

本周在学习Trie数据结构的时候,看到了他的发明者 Edward Fredkin,他也在研究reversible computing 弗雷德金(Fredkin)对计算,硬件和软件一直很感兴趣。 在1960年代初期,他在BBN编写了第一台PDP-1汇编程序。 他是trie数据结构,Fredkin gate和Billiard-Ball计算机模型的可逆计算的发明者。 他的主要贡献包括他在可逆计算和元胞自动机方面的工作。 他还研究领域还包括计算机视觉,人工智能研究和计算机象棋。 ...

2021-01-17 · 1 min · 70 words · Garlic Space

关于Trie

最早提及Trie树的一篇文章

2021-01-16 · 17 min · 3602 words · Garlic Space

LeetCode- Replace Words Solution

题目: In English, we have a concept called root, which can be followed by some other word to form another longer word - let’s call this word successor. For example, when the root "an" is followed by the successor word "other", we can form a new word "another". Given a dictionary consisting of many roots and a sentence consisting of words separated by spaces, replace all the successors in the sentence with the root forming it. If a successor can be replaced by more than one root, replace it with the root that has the shortest length. ...

2021-01-12 · 4 min · 800 words · Garlic Space

docker安装 zookeeper, dubbo-admin

1 . 环境:

2020-12-23 · 1 min · 85 words · Garlic Space

docker安装tomcat

1 . 环境:

2020-12-22 · 1 min · 112 words · Garlic Space

cenos7 docker安装

环境:

2020-12-21 · 1 min · 64 words · Garlic Space

spring boot+maven 生成多模块项目

spring boot + maven配置, 创建一个包含多个模块项目的步骤 项目创建 使用spring的initializr 选择一下就可以生成代码 项目: tongda (jar) 模块: user (war) order (war) common (jar) 配置: Project : Maven Project Language : Java Spring Boot : 2.4.1 Dependencies: Java : 11 Packaging :jar/war 调整 parent POM 修改tongda的pom.xml, 打包类型设置为pom 新增packaging 标签并设置为pom 1 <packaging>pom</packaging> 通知增加模块配置 1 2 3 4 5 <modules> <module>user</module> <module>order</module> <module>common</module> </modules> 各个模块中调整parent标签 order, user模块 pom.xml文件 1 2 3 4 5 6 <parent> <groupId>com.tongda</groupId> <artifactId>tongda</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> 验证 1 2 3 4 5 6 7 8 9 10 11 12 > mvn clean package ... [INFO] Reactor Summary: [INFO] [INFO] tongda 0.0.1-SNAPSHOT .............................. SUCCESS [ 1.250 s] [INFO] user ............................................... SUCCESS [ 9.161 s] [INFO] order .............................................. SUCCESS [ 6.106 s] [INFO] common 0.0.1-SNAPSHOT .............................. SUCCESS [ 4.226 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ... 参考引用 https://www.baeldung.com/maven-multi-module https://github.com/bz51/SpringBoot-Dubbo-Docker-Jenkins Photo by Zaksheuskaya from Pexels

2020-12-21 · 1 min · 140 words · Garlic Space