Python read Excel file

Source: Internet
Author: User

I. Description of the XLRD

XLRD is a module that is designed to read Excel documents in Python and needs to be installed before use.

You can download the tar.gz file to this https://pypi.python.org/pypi/xlrd, then unzip the installation, switch to the extracted folder in the cmd command window, and use

Python setup.py Install

For installation.

Method Two,

Using PIP for installation

Pip Install Xlrd

Second, the use of the introduction

1 Importing Modules

Import xlrd

2 Open an Excel file

data = Xlrd.open_workbook (' Excelfile.xls ')

3 Get a worksheet method

Table = data.sheets () [0] #通过索引顺序获取

table = data.sheet_by_index (0) #通过索引顺序获取

Table = data.sheet_by_name (U ' Sheet1 ') #通过名称获取 4 Gets the value of the entire row or column,--> returns the array table.row_values (i) table.col_values (i) 5 gets the number of rows and columns N rows = Table.nrowsncols = Table.ncols6 Loop table gets row data,---> Return data    For i in range (nrows):Print Table.row_values (i) 7 cellcell_a1 = Table.cell (0,0). Value  CELL_C4 = Table.cell (2,3). Value can also be indexed with a row number cell_a1 = Table.row (0) [0].value cell_a2 = Table.col (1) [0].value 8 sheet some Property name Gets the name of the sheet at this time, print Table.name

  

Python read Excel file

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.