0

我正在尝试使用 python 从 Excel 获取数据以在电报机器人中发送消息,例如:用户输入他的区域它是检查区域,然后输入数字并检查数字,然后所有用户获取数据。谢谢你。

代码:

  elif message.text.lower() == 'get data':
        path = "Test.xlsx"
        # To open the workbook
        # workbook object is created
        wb_obj = openpyxl.load_workbook(path)

        # Get workbook active sheet object
        # from the active attribute
        sheet_obj = wb_obj.active

        # Cell object is created by using
        # sheet object's cell() method.
        cell_obj = sheet_obj['A': 'B']
      
        # Print value of cell object
        # using the value attribute
        for cell1, cell2 in cell_obj:
            print('excel read')
        bot.send_message(message.chat.id, text='Enter region:', reply_markup=menu3)
        if message.text.lower() == cell1:
            bot.send_message(message.chat.id, text='Enter number:', reply_markup=menu3)
        if message.text.lower() == cell2:
            bot.send_message(message.chat.id, f'Your data:\n\n{cell2()}')
4

0 回答 0