从python中的excelsheet读取特定的单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19480449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reading particular cell value from excelsheet in python
提问by npatel
I want to get particular cell values from excelsheet in my python script.
I came across xlrd
, xlwt
, xlutils
modules for reading/writing to/from excelsheet.
我想从我的 python 脚本中的 excelsheet 获取特定的单元格值。我遇到了xlrd
, xlwt
,xlutils
用于从 excelsheet 读取/写入/写入的模块。
I created myfile.xls with hi, hello, how in first column's 3 cells.
我创建了 myfile.xls,你好,你好,如何在第一列的 3 个单元格中。
sample code :-
示例代码:-
import xlrd
workbook = xlrd.open_workbook('myfile.xls')
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = -1
while curr_row < num_rows:
curr_row += 1
row = worksheet.row(curr_row)
print row
output :-
输出 :-
[text:u'hi']
[text:u'hello']
[text:u'how']
I want to read specific cell values from excelsheet, can someone suggest me if there is a way to do that?
我想从 excelsheet 中读取特定的单元格值,如果有办法做到这一点,有人可以建议我吗?
采纳答案by StvnW
To access the value for a specific cell you would use:
要访问特定单元格的值,您将使用:
value = worksheet.cell(row, column)
value = worksheet.cell(row, column)
回答by jebran
The code below will help you in solving the problem:
下面的代码将帮助您解决问题:
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = 0
while curr_row < num_rows:
curr_row += 1
row = worksheet.row(curr_row)
print row[0].value
回答by Bharath_Raja
To access the value for a specific cell:
要访问特定单元格的值:
cell_value = worksheet.cell(row_number, column_number).value