Python xlwt writing Excel files

Source: Internet
Author: User

Python writes Excel files and requires XLWT libraries. : https://pypi.python.org/pypi/xlwt/1.1.2

After download, modify the extension to RAR and install after decompression:

Once the installation is successful, it can be referenced. The following code:

#-*-Coding:utf-8-*-

Import XLWT

"' Write content to Excel cells, write one line at a time sheet: page signature; row: Row table of Contents; RowIndex: Row index" '
def writesheetrow (Sheet,rowvaluelist,rowindex):
i = 0
For svalue in Rowvaluelist:
strvalue = Unicode (str (svalue), ' Utf-8 ')
Sheet.write (Rowindex,i,strvalue)
i = i + 1


"Write Excel File"
def save_excel (strfile):
Excelfile = Unicode (strfile, "UTF8")
WBK = XLWT. Workbook ()
Sheet = wbk.add_sheet (' Sheet1 ')
Headlist = [' Heading 1 ', ' Heading 2 ', ' Heading 3 ', ' Title 4 ']
RowIndex = 0
Writesheetrow (Sheet,headlist,rowindex)
For I in Xrange (1,11):
RowIndex = RowIndex + 1
ValueList = []
For j in Xrange (1,5):
Valuelist.append (J*i)
Writesheetrow (Sheet,valuelist,rowindex)
Wbk.save (Excelfile)

#测试
Save_excel ("D:\\test.xlsx")

The results are as follows:

Python xlwt writing Excel files

Related Article

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.