python_xecel
- 移动并重命名工作簿
1 from pathlib import Path # 导入pathlib模块的path类
2 import time
3
4 # Press the green button in the gutter to run the script.
5 if __name__ == '__main__':
6 data = time.strftime('%y-%m-%d %H:%M:%S')
7
8 old_file_path = Path('D:\\demo\\python\\test_excel\\file_from\\test.xlsx') # 这里的Path,等价于os.path,join();参考第10行代码
9 new_file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
10 # test_path = Path('D:', 'demo', 'python', 'test_excel', 'file_from', 'test.xlsx')
11 old_file_path.rename(new_file_path) # 剪切并重命名
12
13 if new_file_path.is_file():
14 print(f'{data}:{old_file_path} rename successed')
- 解析工作簿的路径信息
1 from pathlib import Path # 导入pathlib模块的path类
2 import time
3
4 # Press the green button in the gutter to run the script.
5 if __name__ == '__main__':
6 data = time.strftime('%y-%m-%d %H:%M:%S')
7 file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
8 # 解析工作簿的路径信息
9 path = file_path.parent
10 # 打印文件所在路径
11 print(f'文件路劲----:{path}')
12 file_name = file_path.name
13 # 打印文件名字
14 print(f'文件名为----:{file_name}')
15 suffix = file_path.suffix
16 # 打印文件后缀名
17 print(f'文件后缀名为----:{suffix}')
- 提取文件夹内所有工作簿的文件名
1 from pathlib import Path # 导入pathlib模块的path类
2
3 # Press the green button in the gutter to run the script.
4 if __name__ == '__main__':
5 folder_path = Path('D:\\demo\\python\\test_excel\\file_to')
6 file_list = folder_path.glob('*.xlsx')
7 print(f'file_list----:{file_list}')
8 lists = []
9 for test in file_list:
10 file_name = test.name
11 lists.append(file_name)
12 print(f'lists----:{lists}')
随机推荐
- Postman POST多个文件
软件做的比较好用,
- FastJson转Java对像字段不区分大小写
昨天遇到参数key大小写不一致导致校验签名失败的问题,查了很长时间才找到原因.看了一下FastJson源码,发现JSON.toObject中转换成对象的时候会忽略大小写. 所以,当使用了JSON.to ...
- 电脑网卡把报文的vlan tag去掉
1 现象 现象说明:从电脑的网卡(用的Realtek)进来一个带vlan tag的报文,但是使用wireshark抓取的报文没有vlan tag. 解决方式如下:需要注册表. 参考链接1:https: ...
- 架构与思维:了解Http 和 Https的区别(图文详解)
1 介绍 随着 HTTPS 的不断普及和使用成本的下降,现阶段大部分的系统都已经开始用上 HTTPS 协议. HTTPS 与 HTTP 相比, 主打的就是安全概念,相关的知识如 SSL .非对称加密. ...
- redis数据类型篇
redis数据类型官网资料,https://redis.io/docs/manual/data-types/ 生产环境下的redis实况图 超哥这个redis实例里,db0库有140万个key. 1. ...
- 在 Wed 中应用 MyBatis(同时使用MVC架构模式,以及ThreadLocal 事务控制)
1. 在 Wed 中应用 MyBatis(同时使用MVC架构模式,以及ThreadLocal 事务控制) @ 目录 1. 在 Wed 中应用 MyBatis(同时使用MVC架构模式,以及ThreadL ...
- Java中创建对象的5种方式总结
引言 作为Java开发人员,我们每天都会代码中创建对象,但我们通常使用依赖管理系统,比如Spring框架,然后,这里有很多种创建对象的方式,本文就对Java创建对象的几种方式进行总结 五种创建方式 创 ...
- 阿里云安全扫描漏洞修复fastjson,jackson,xstream,redis, 微信支付xml转对象 ForbiddenClassException
阿里云安全扫描漏洞修复fastjson,jackson,xstream,redis 1.fastjson漏洞fastjson爆发新的反序列化远程代码执行漏洞,黑客利用漏洞,可绕过autoType限制, ...
- EyeLink 1000 plus(桌面式)眼动仪使用指导
一.简介 眼动追踪是测量眼睛运行的过程.眼动追踪研究的最关注的事件是确定人类或者动物看的地方(比如:"注视点"或"凝视点").更准确来说是通过仪器设备进行图像处 ...
- 18-Docker资源限制
背景 若容器使用的计算机资源不加限制,那么,可能会耗光整个计算机资源. 如代码里有bug,出现了死循环,且创建了很多线程. 在Docker中,可以使用Cgroup技术限制CPU.Block IO.RA ...