如何在python中的xlsx工作表中搜索多个项目

时间:2019-01-14 07:57:20

标签: python nlp tokenize

我从用户处获取输入,然后对其进行标记化,标记化成功,但是我面临的问题是它什么都不显示

我正在尝试在用户输入的xlsx文件中搜索单词,然后应显示该特定单词所在的完整行。

import xlrd
import pandas as pd
from openpyxl import load_workbook
from xlrd import open_workbook
from nltk import word_tokenize


sen = input("Enter your sentence: ")
sent = word_tokenize(sen)
print(sent)


book = open_workbook("Pastho dictionary.xlsx")
for sheet in book.sheets():
    for rowidx in range(sheet.nrows):
        row = sheet.row(rowidx)
        for colidx,cell in enumerate(row):
            for i in sent:
                if cell.value == sent:#row value
                    print ("Found Row Element")
                    print(rowidx, colidx)
                    print(cell.value)
                    print(row)

我希望搜索所有输入的单词,然后显示该单词所在的整行。

1 个答案:

答案 0 :(得分:0)

这就是我要去的地方:

import xlwings as xw

bookName = r'first.xlsx'
sheetName = 'Sheet1'

wb = xw.Book(bookName)
sht = wb.sheets[sheetName]

myCell = wb.sheets[sheetName].api.UsedRange.Find('pankaj')

print(myCell.address)

信用:https://www.vitoshacademy.com/how-to-search-in-a-worksheet-with-python/