我希望能够比较每行中给定列的值和另一个值,如果这些值相等,我想将整个行复制到另一个电子表格中。如何使用Python实现这一点?谢谢!
xlrd
(用于读取Excel)/xlwt
(用于写入Excel)。你可以访问http://www.python-excel.org/了解更多信息。import xlrd
fname = "sample.xls"
bk = xlrd.open_workbook(fname)
shxrange = range(bk.nsheets)
try:
sh = bk.sheet_by_name("Sheet1")
except:
print "no sheet in %s named Sheet1" % fname
return None
nrows = sh.nrows
ncols = sh.ncols
print "nrows %d, ncols %d" % (nrows,ncols)
cell_value = sh.cell_value(1,1)
print cell_value
row_list = []
for i in range(1,nrows):
row_data = sh.row_values(i)
row_list.append(row_data)
如果你正在处理Excel 2007,那么使用openpyxl
: http://packages.python.org/openpyxl/