Home  >  Article  >  Backend Development  >  python processing Excel xlrd

python processing Excel xlrd

高洛峰
高洛峰Original
2016-10-18 10:35:261516browse

The module commonly used by python to process Excel is xlrd. It is very convenient to use xlrd to process Excel documents. The basic usage is introduced below

1. Open the file

import xlrd

data= xlrd.open_workbook("c:\skills.xls")

Get a worksheet

table = data.sheet_by_name(u'skills') #Also

table = data.sheet_by_index(0)

row, column acquisition

table.row_values(i)

table.col_values(i)

row Number, number of columns, etc.

nrows = table.nrows

ncols = table.ncols

Cell data

cell_A1 = table.cell(0, 0).value

cell_C4 = table.cell(2, 3) .value

#Simple write cell

table.put_cell(row, col, ctype, value, xf)

row = col = 0

ctype = 1 # 0 empty , 1 string, 2 number, 3 date, 4 bool, 5 error

value = 'this is cell value'

xf = 0


For more functions, please refer to the official documentation

https://secure.simplistix.co.uk/svn/xlrd/ trunk/xlrd/doc/xlrd.html?p=4966


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python FTP transferNext article:Python FTP transfer