[Python]python之xlwt模块列宽width、行高Heights详解
2016-09-25 15:52
555 查看
转自:http://www.3fwork.com/b204/001224MYM011551/
python之xlwt模块列宽width、行高Heights详解 今天用python操作excel时,发现xlwt的API中没有对width、height有更多介绍,且使用时也不知道width取多少合适。现在这做个详细介绍
使用版本:
python:2.7.5
xlwt:1.0.0
一:先创建一个excel
二、设置列宽度
xlwt中列宽的值表示方法:默认字体0的1/256为衡量单位。
xlwt创建时使用的默认宽度为2960,既11个字符0的宽度
所以我们在设置列宽时可以用如下方法:
width = 256 * 20 256为衡量单位,20表示20个字符宽度
那接下来完成我们的程序
效果就如下:
三、行高
行宽是在单元格的样式中设置的,你可以通过自动换行通过输入文字的多少来确定行高
一般如下方法:
效果如下:
四、其它
在xlwt中没有特定的函数来设置默认的列宽及行高
参考文档: http://reliablybroken.com/b/2011/10/widths-heights-with-xlwt-python/
python之xlwt模块列宽width、行高Heights详解 今天用python操作excel时,发现xlwt的API中没有对width、height有更多介绍,且使用时也不知道width取多少合适。现在这做个详细介绍
使用版本:
python:2.7.5
xlwt:1.0.0
一:先创建一个excel
''' Created on 2015-11-19 @author: Administrator ''' import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('sheet1')
二、设置列宽度
xlwt中列宽的值表示方法:默认字体0的1/256为衡量单位。
xlwt创建时使用的默认宽度为2960,既11个字符0的宽度
所以我们在设置列宽时可以用如下方法:
width = 256 * 20 256为衡量单位,20表示20个字符宽度
那接下来完成我们的程序
#coding:utf-8
''' Created on 2015-11-19 @author: Administrator ''' import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('sheet1')
first_col=sheet.col(0) #xlwt中是行和列都是从0开始计算的
sec_col=sheet.col(1)
first_col.width=256*20
book.save('width.xls')
效果就如下:
三、行高
行宽是在单元格的样式中设置的,你可以通过自动换行通过输入文字的多少来确定行高
一般如下方法:
#coding:utf-8
''' Created on 2015-11-19 @author: Administrator ''' import xlwt book = xlwt.Workbook(encoding='utf-8') sheet = book.add_sheet('sheet1')
first_col=sheet.col(0)
sec_col=sheet.col(1)
first_col.width=256*20
tall_style = xlwt.easyxf('font:height 720;') # 36pt,类型小初的字号
first_row = sheet.row(0)
first_row.set_style(tall_style)
book.save('width.xls')
效果如下:
四、其它
在xlwt中没有特定的函数来设置默认的列宽及行高
参考文档: http://reliablybroken.com/b/2011/10/widths-heights-with-xlwt-python/
相关文章推荐
- python之xlwt模块列宽width、行高Heights详解
- python操作excel之xlrd、xlwt模块详解
- Python使用xlwt模块操作Excel的方法详解
- python模块(使用xlrd、xlwt操作excel表格详解)
- Python中time模块详解
- python模块:win32com用法详解
- python time模块详解
- 详解Python模块导入方法
- python 模块导入问题详解
- python的time模块功能详解
- Python中time模块详解
- python time模块详解(转)
- python之import模块详解
- python os.path模块常用方法详解
- Python详解之模块:re (待续)
- python sys模块详解
- 详解Python模块导入方法
- python模块之---- urllib2模块详解
- python:time模块详解
- python模块:win32com用法详解