Chinaunix首页 | 论坛 | 博客
  • 博客访问: 425165
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1101
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-20 19:29
个人简介

http://meetbill.github.io/

文章分类

全部博文(121)

我的朋友

分类: LINUX

2016-06-14 22:47:23

python编辑xls工具


python xlwt设置列宽度
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')  

阅读(8033) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~