Python xlwt module detailed description of column width and Row Height Heights,

Source: Internet
Author: User

Python xlwt module detailed description of column width and Row Height Heights,

When I used python to Operate excel today, I found that the xlwt API does not provide more information on width and height, and I do not know how much width is suitable for use. Here is a detailed introduction.

Version used:

Python: 2.7.5

Xlwt: 1.0.0

1. Create an excel file first

'''Created on 2015-11-19@author: Administrator'''import xlwtbook = xlwt.Workbook(encoding='utf-8')sheet = book.add_sheet('sheet1')

Ii. Set column width

In xlwt, the column width is expressed as 1/256 of the default font 0.
When xlwt is created, the default width is 2960, which is the width of 11 characters and 0 characters.

So we can use the following method when setting the column width:

Width = 256*20 256 is the unit of measurement. 20 represents the width of 20 characters.

Then complete our program.

# Coding: UTF-8 ''' Created on @ author: Administrator ''' import xlwtbook = xlwt. workbook (encoding = 'utf-8') sheet = book. add_sheet ('sheet1') first_col = sheet. col (0) # In xlwt, the rows and columns are calculated from 0. sec_col = sheet. col (1) first_col.width = 256*20 book.save('width.xls ')

The effect is as follows:

3. Row Height

The row width is set in the cell style. You can use the automatic line feed to determine the Row Height by the number of input text.

The general method is as follows:

# Coding: UTF-8 ''' Created on @ author: Administrator ''' import xlwtbook = xlwt. workbook (encoding = 'utf-8') sheet = book. add_sheet ('sheet1') first_col = sheet. col (0) sec_col = sheet. col (1) first_col.width = 256 * 20tall_style = xlwt. easyxf ('font: height 720; ') # 36pt, the font size of the initial type, first_row = sheet.row(01_first_ro1_set_style(tall_style1_book.save('width.xls ')

The effect is as follows:

4. Others

There is no specific function in xlwt to set the default column width and Row Height.

 

Reference:

Http://reliablybroken.com/ B /2011/10/widths-heights-with-xlwt-python/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.