python写入已存在的excel数据
来源:互联网 发布:xampp是什么软件 编辑:程序博客网 时间:2024/05/20 20:21
python可以使用xlrd读excel,使用xlwt写excel,但是如果要把数据写入已存在的excel,需要另外一个库xlutils配合使用.
大概思路:
1、用xlrd.open_workbook打开已有的xsl文件
注意添加参数formatting_info=True,得以保存之前数据的格式
2、然后用,from xlutils.copy import copy;,之后的copy去从打开的xlrd的Book变量中,拷贝出一份,成为新的xlwt的Workbook变量
3、然后对于xlwt的Workbook变量,就是正常的:
通过get_sheet去获得对应的sheet,拿到sheet变量后,就可以往sheet中,写入新的数据
4、写完新数据后,最终save保存
源码例子:
import xlrdimport osfrom xlutils.copy import copyfrom xlwt import Styledef writeExcel(row, col, str, styl=Style.default_style): rb = xlrd.open_workbook(file, formatting_info=True) wb = copy(rb) ws = wb.get_sheet(0) ws.write(row, col, str, styl) wb.save(file)style = xlwt.easyxf('font:height 240, color-index red, bold on;align: wrap on, vert centre, horiz center');writeExcel(1, 1, 'hello world', style)
如果需要excel原格式,需要加参数
formatting_info=True
如果需要加excel样式,传入样式字符串给xlwt.easyxf即可
合并单元格:
ws.write_merge(top_row, bottom_row, left_column, right_column, string)
0 0
- python写入已存在的excel数据
- 用Python将数据写入已存在Excel
- C#实现向已存在的Excel文件中写入数据实例(两种方法)
- 【整理】Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据
- 数据导入到已存在的excel表格中
- java 向已存在的excel中追加数据
- java 向已存在的excel中追加数据 .
- 打开已存在的Excel
- python更改已存在excel文件
- python数据写入excel表格
- python 将数据写入excel
- 写入已经存在的excel表
- c# 向已存在的excel中追加数据,oledb的方式
- Excel 数据的读取写入
- 用python将excel数据写入mysql
- Python中向excel中写入数据
- Python向excel中写入数据
- 向存在的文件中写入数据
- 专业术语随记
- 关于Android 开发中的一些常用权限
- Disruptor(无锁并发框架)-发布
- error: no such file or directory
- Oracle EBS Forms查看trace file
- python写入已存在的excel数据
- .NET之特性和属性
- Java7语法新特性
- Editext去掉视觉回显
- Linux MTD系统剖析
- 关于Android 开发中的一些常用框架
- 通过Form类来获取DEV的BarManager控件。
- DVRRDK, EZSDK和DVSDK这三者有什么区别
- oracle分页在ibatis中配置代码块