python根据excel内容生成文件夹

python根据excel内容生成文件夹 工作需要根据excel数据信息,生成对应的文件夹,用python写了一个脚本处理了一下。 样例中表格内容也进行了调整。 环境: windows10 python3.7 + openpyxl 目标: 以list.xlsx数据为准,抽取指定sheet页中的指定字段信息,生成目录, 并在目录中创建固定的子目录. 表格格式: 表格sheet-A01 序号 项目名称 备注 1 项目1 张三 2 项目2 李四 表格sheet-A02 序号 项目名称 备注 1 项目1 王五 每一个sheet存放一个批次的任务信息, total为批次名称 代码: 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 63 64 65 66 67 68 69 70 71 72 from openpyxl import load_workbook from openpyxl import Workbook import os import re ## 获取项目清单列表 wb = load_workbook( filename = '.\\test\\list.xlsx') #ws_in = wb_in.active outpath=".\\out\\" ## 名字列表开始结束行号 start_index = 4 ##end_index = ## 目录编号 dir_no = 1 ## 1. 找到指定的sheet页面 sheets_name = ['A01', 'A02'] ## 3. 组成符合要求的目录字符串创建目录 def mkdir(path): try: os.makedirs(path) print("CREATE") except FileExistsError: print("EXIST, NO CREATE") # Get all dirs def mksubdir(path): try: dirnames = [name for name in os.listdir('.\\model') if os.path.isdir(os.path.join('.\\model', name))] for i in dirnames: mkdir(path+"\\"+i) except : print(" CREATE SUB DIR ERROR ") for i in range(len(sheets_name)): print(i) sheet = wb[sheets_name[i]] print(sheet) ## 2. 找到相关的任务信息 for row in range(start_index, sheet.max_row+1): ## 1. 判断内容是否空格 0 or 1? if (str(sheet.cell(row, column=1).value).strip() == "None" ): print(batch_no + " is over") break; ##2. 获取表格内容生成目录 task_no = sheet.cell(row, column=1).value batch_no = sheet.title.split('-')[0] task_context = str(sheet.cell(row, column=2).value).strip() task_manager = re.search(r'张三|李四|王五', sheet.cell(row,column=3).value) task_leader = task_manager.group(0) #(序号)-批次号-批次序号-任务名称(负责人) # mkdir(path) dir_no_str = format(dir_no, '02d') task_no_str = format(task_no, '02d') dirname=dir_no_str+"-"+batch_no+"-"+task_no_str+"-"+task_context+"-"+task_leader mkdir(outpath+dirname) # mksubdir(path) mksubdir(outpath+dirname) dir_no = dir_no+1 运行结果 ├─01-A01-01-项目1-张三 │ ├─01_文档目录1 │ └─02_文档目录2 ├─02-A01-02-项目2-李四 │ ├─01_文档目录1 │ └─02_文档目录2 └─03-A02-01-项目3-王五 ├─01_文档目录1 └─02_文档目录2 ...

2020-05-01 · 2 min · 286 words · Garlic Space

通过inode删除特殊字符文件

对于正常使用rm无法删除的文件可以通过查找inode进行删除 1 2 ls -i find -inum xxx -delete or 1 2 ls -i find -inum xxx -exec rm -i {} \; 直接删除 1 2 3 4 5 6 7 8 9 [root@centosgpt vm]# ls -i 2278688 > 13592459 memdump2.c~ 13592454 memzero 7506486 test.c~ 2275894 118902.mem 2275882 memdump2.py 13592461 memzero.c 9733651 translate ... [root@centosgpt vm]# find -inum 2278688 -delete [root@centosgpt vm]# ls 118902.mem idle.py~ memdump3.c memory_layout processwrite.c test.c~ vsyscall.c 18 memdump memdump4 memory_layout.c processwrite.c~ translate 交互式 1 2 3 4 5 6 7 8 9 [root@centosgpt vm]# ls -i 7506464 > 13592459 memdump2.c~ 13592454 memzero 7506486 test.c~ 2275894 118902.mem 2275882 memdump2.py 13592461 memzero.c 9733651 translate [root@centosgpt vm]# find -inum 7506464 -exec rm -i {} \; rm: remove regular empty file ‘./>’? y [root@centosgpt vm]# ls 118902.mem idle.py~ memdump3.c memory_layout processwrite.c test.c~ vsyscall.c 18 memdump memdump4 memory_layout.c processwrite.c~ translate

2020-04-16 · 1 min · 138 words · Garlic Space

python汇总excel数据

工作需要汇总整理相关excel数据信息,并按照规定格式进行反馈,用python写了一个脚本处理了一下。 样例中表格内容也进行了调整。 环境: windows10 python3.7 + openpyxl 目标: 以data1数据为准,通过查找data2补全相关信息, 将数据填入要求的result文件中。 表格格式: 表格1 data1.xlsx 姓名 张三 李四 表格2 data2.xlsx 序号 姓 名 性别 身份证号 联系电话 01 张三 男 130012345678901234 13911111111 02 李四 男 123012345678901234 13922222222 03 王五 男 123012345678901234 13933333333 表格3 result.xlsx 序号 所属部门 厂商 姓名 身份证号 联系电话 备注 代码: 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 from openpyxl import load_workbook from openpyxl import Workbook import pandas as pd wb_in = load_workbook( filename = '.\\test\\data1.xlsx') ws_in = wb_in.active ## 名字列表开始结束行号 start_index = 2 end_index = 4 wb_info = load_workbook( filename = '.\\test\\data2.xlsx') ws_info = wb_info.active wb_out = load_workbook( filename = '.\\test\\result.xlsx') ws_out = wb_out.active out_index = 2 ## 找到要统计人员姓名 for x in range(start_index,end_index): name = ws_in.cell(row=x,column=1) print(name.value) ## 查找要统计人员附件信息并更新到统计表格中 find_flag = 0 for row in ws_info.iter_rows("B"): for col in row: #print(col.value) if (str(col.value).strip() == str(name.value).strip()) and (find_flag == 0): ## 第四列 身份证 第五列 联系电话 idno = ws_info.cell(row=col.row,column=4) phoneno = ws_info.cell(row=col.row, column=5) ## 更新到统计文件 ws_out['A'+ str(out_index)].value = str(out_index-1) ws_out['B'+ str(out_index)].value = 'XX部' ws_out['C'+ str(out_index)].value = 'XXX' ws_out['D'+ str(out_index)].value = name.value ws_out['E'+ str(out_index)].value = idno.value ws_out['F'+ str(out_index)].value = phoneno.value out_index = out_index + 1 find_flag = 1 break if find_flag == 0: print(name.value) wb_out.save( filename = '.\\test\\result.xlsx') 运行结果 序号 所属部门 厂商 姓名 身份证号 联系电话 备注 1 XX部 XXX 张三 130012345678901234 13911111111 2 XX部 XXX 李四 130012345678901234 13922222222 参考 Openpyxl Doc Using openpyxl to find rows that contain cell with specific value (Python 3.6)

2020-01-31 · 2 min · 267 words · Garlic Space

putty免密登录SSH服务

cenos7X86_64 + openssh - windows10 - putty

2019-12-31 · 1 min · 96 words · Garlic Space

Linux Swap 分区相关命令

/proc/swaps 文件

2019-11-03 · 1 min · 140 words · Garlic Space

查看进程内存布局

进程内存布局 可以通过一下方法查看: 命令: pmap 文件: proc filesystem maps 使用 pmap 可以从其说明看到 -X 也是从/proc/PID/smaps获取了更详细的信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [root@centosgpt ~]# pmap 1704 1704: -bash 0000000000400000 884K r-x-- bash 00000000006dd000 4K r---- bash 00000000006de000 36K rw--- bash ... 00007f3c65515000 28K r--s- gconv-modules.cache 00007f3c6551c000 4K rw--- [ anon ] 00007f3c6551d000 4K r---- ld-2.17.so 00007f3c6551e000 4K rw--- ld-2.17.so 00007f3c6551f000 4K rw--- [ anon ] 00007ffd64655000 132K rw--- [ stack ] 00007ffd64769000 12K r---- [ anon ] 00007ffd6476c000 4K r-x-- [ anon ] ffffffffff600000 4K r-x-- [ anon ] total 115580K 查看 proc filesystem maps /proc/PID/smaps ...

2019-10-19 · 1 min · 179 words · Garlic Space

进程中线程查看及线程栈查看

进程线程查看 可以通过一下方法查看: 命令: ps top pidstat pstree 文件: proc filesystem 使用 ps ps与线程相关的参数 1 2 3 4 5 6 THREAD DISPLAY H Show threads as if they were processes. -L Show threads, possibly with LWP and NLWP columns. m Show threads after processes. -m Show threads after processes. -T Show threads, possibly with SPID column. 使用-L ps -eLo pid,tid,tgid,pgrp,args 1 2 3 4 5 6 7 [root@centosgpt ~]# ps -eLo pid,tid,tgid,pgrp,args|grep python 1173 1173 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1594 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1595 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1596 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1613 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 77189 77189 77189 77188 grep --color=auto python 使用-m显示 ps -mLe ...

2019-10-12 · 13 min · 2567 words · Garlic Space

Graph-Easy ascii图片绘制

环境:

2019-09-07 · 2 min · 264 words · Garlic Space

Linux 与 Windows 文本文件格式转换

由于Windows与Linux对换行的定义不同,导致Windows应用不能正常按行显示Linux文本,Linux显示Windows文本时会带有^M

2019-09-01 · 1 min · 183 words · Garlic Space

awk中的'数组'

awk中的’数组‘是一种关联数组,又称作maps、字典,他的索引不需要连续, 可以使用字符串、数字做为索引, 此外,不需要事先声明数组的大小 - 数组可以在运行时扩展/收缩。 语法: 赋值: 1 array_name[index] = value 删除: 1 delete array_name[index] 多维数组(使用字符串模拟) 1 array["0,0"] = 100 遍历: 1 2 for (var in arrayname) actions 实例 统计汇总 数据:Iplogs.txt 1 2 3 4 5 6 7 8 180607 093423 123.12.23.122 133 180607 121234 125.25.45.221 153 190607 084849 202.178.23.4 44 190607 084859 164.78.22.64 12 200607 012312 202.188.3.2 13 210607 084849 202.178.23.4 34 210607 121435 202.178.23.4 32 210607 132423 202.188.3.2 167 total.awk: 1 2 3 4 5 6 7 { Ip[$3]++; } END { for (var in Ip) print var, "access", Ip[var]," times" } 注意下END后的{需要和END在一行 输出: 1 2 3 4 5 6 $ awk -f total.awk Iplogs.txt 123.12.23.122 access 1 times 164.78.22.64 access 1 times 202.188.3.2 access 2 times 125.25.45.221 access 1 times 202.178.23.4 access 3 times 说明: $3是一个IP地址, Ip做为数组的索引。 对于每一行,它会增加相应IP地址索引的值。 最后在END部分中,所有索引都将是唯一IP地址的列表,其对应的值是出现次数。 ...

2019-08-31 · 4 min · 728 words · Garlic Space