如何将打印值从一个 sheet 写入新创建的值

How to write printed value from one sheet to newly created one

我是 Python 的新手,所以只是刚刚掌握它,非常感谢您的帮助,因为我不知道如何将文件 A 中的值写入文件 B。

我愿意:

  1. 从 'mf_mar_2018.xls' 中过滤 D 列的值('saxon' 的过滤器)
  2. 将找到的值写入名为 'saxons.xls'
  3. 的新文件

我能够获取未过滤的值并在终端中打印它们。

我的脚本如下:

#import the writer
import xlwt
#open the spreadsheet
workbook = xlwt.Workbook()
#add a sheet named "Club BFA ranking"
worksheet1 = workbook.add_sheet("Club BFA ranking")
#in cell 0,0 (first cell of the first row) write "Ranking"
worksheet1.write(0, 0, "Ranking")
#in cell 0,1 (second cell of the first row) write "Name"
worksheet1.write(0, 1, "Name")
#save and create the spreadsheet file
workbook.save("saxons.xls")

#import the reader
import xlrd
#open the rankings spreadsheet
book = xlrd.open_workbook('mf_mar_2018.xls')
#open the first sheet
first_sheet = book.sheet_by_index(0)
#print the values in the second column of the first sheet
print first_sheet.col_values(1)

尝试这样的事情。

name = []
rank = []
for i in range(first_sheet.nrows):
    #print(first_sheet.cell_value(i,3)) 
    if('Saxon' in first_sheet.cell_value(i,3)):  
        name.append(first_sheet.cell_value(i,2))
        rank.append(first_sheet.cell_value(i,8))    
        print('a')
for j in range(len(name)):
    worksheet1.write(j+1,0,rank[j])
    worksheet1.write(j+1,1,name[j])


workbook.save("saxons.xls")