用python读取excel
来源:互联网 发布:java中什么是构造器 编辑:程序博客网 时间:2024/05/01 04:49
读取xls文件:import xlrd
获取xls文件
workbook = xlrd.open_workbook('xxx.xls')
获取表单数量
workbook.nsheets
获取一个表单
workbook.sheets()[i]
workbook.sheet_by_index(i)
workbook.sheet_by_name('sheet1')
访问数据
sheet.cell(i,j).value
sheet.row(i)[j].value
sheet.col(j)[i].value
写xls文件: import xlwt
book = xlwt.Workbook(encoding = 'utf-8',style_compression = 0)
sheet = book.add_sheet('dada',cell_overwrite_ok = True)
sheet.write(i,j,content)
book.save(path)
写入xls文件设置格式
设置背景色:
style = xlwt.easyxf('pattern: pattern solid, fore_color yellow;')
设置加粗
style = xlwt.easyxf('font: bold 1')
设置对齐:
alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_LEFT
horz_style = xlwt.XFStyle()
horz_style.alignment = alignment
---------其实不用这么复杂-------------following show the answer
xlwt.easyxf("pattern:pattern solid,fore_color yellow;font:color white;align:horizright")
设置列宽:
sheet.col(0).width = 256 * (len(key) + 1)
自动换行:
style = xlwt.easyxf('align: wrap on')
sheet.write(0, 0, 'Firstname', style)
获取xls文件
workbook = xlrd.open_workbook('xxx.xls')
获取表单数量
workbook.nsheets
获取一个表单
workbook.sheets()[i]
workbook.sheet_by_index(i)
workbook.sheet_by_name('sheet1')
访问数据
sheet.cell(i,j).value
sheet.row(i)[j].value
sheet.col(j)[i].value
写xls文件: import xlwt
book = xlwt.Workbook(encoding = 'utf-8',style_compression = 0)
sheet = book.add_sheet('dada',cell_overwrite_ok = True)
sheet.write(i,j,content)
book.save(path)
写入xls文件设置格式
设置背景色:
style = xlwt.easyxf('pattern: pattern solid, fore_color yellow;')
设置加粗
style = xlwt.easyxf('font: bold 1')
设置对齐:
alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_LEFT
horz_style = xlwt.XFStyle()
horz_style.alignment = alignment
---------其实不用这么复杂-------------following show the answer
xlwt.easyxf("pattern:pattern solid,fore_color yellow;font:color white;align:horizright")
设置列宽:
sheet.col(0).width = 256 * (len(key) + 1)
自动换行:
style = xlwt.easyxf('align: wrap on')
sheet.write(0, 0, 'Firstname', style)
1 0
- 用python读取excel
- 用Python读取数据库写进EXCEL
- 用Python读取excel中的数据
- 用xlrd读取excel表格(python)
- python读取excel
- python 读取excel --zhaokuo719
- python 读取excel
- python读取EXCEL
- python读取excel
- python 读取Excel
- Python excel文件读取
- Python 读取excel
- python读取excel文件
- python读取excel文件
- python 读取不规则excel
- python读取excel数据
- python读取excel数据
- python 读取excel数据
- 代码添加约束
- hadoop2.6.0 集群配置
- aaa
- 轻松理解Java动态代理
- ext js
- 用python读取excel
- iOS类别(Category)与扩展(Extension)
- Eclipse创建Maven Project和Maven Module
- Linux如何修改主机名
- 新浪笔试题(二)
- flickr的分表全局唯一id实现方式
- wqw
- Android开发中如何保存用户名密码在本地
- leetcode笔记--Delete Node in a Linked List