Python reads Excel

Source: Internet
Author: User

First, to the python website download http://pypi.python.org/pypi/xlrd module installation,

sudo python setup.py install

Second, the use of the introduction

1. Import Module

Import xlrd

2. Open Excel file to read data

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

3, the use of skills

Get a worksheet

table = data.sheets () [0] # obtained by index order

table = Data.sheet_by_index (0) # gets by index order

table = data.sheet_by_name (U ' Sheet1 ') # gets by name

Get the values (arrays) for the entire row and the entire column

table.row_values (i)table.col_values (i)

Get the number of rows and columns

  

nrows = table.nrows

ncols = Table.ncols

cyclic row and column table data

For i in range (nrows):

Print table.row_values (i)

Cell Cell

cell_a1 = Table.cell (0,0). Value

cell_c4 = Table.cell (2,3). Value

using row and column indexes

cell_a1 = table.row (0) [0].value

cell_a2 = table.col (1) [0].value

a simple write

row = 0

col = 0

# type 0 empty,1 string, 2 number, 3 date, 4 Boolean, 5 error

CType = 1 value = ' cell values '

XF = 0 # Extended Formatting

Table.put_cell (Row, col, CType, value, XF)

Table.cell (0,0) #单元格的值 '

Table.cell (0,0). Value #单元格的值 '

Python reads Excel

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.