During the execution of the Python notebook I want to prompt the user for a range in the Excel workbook in order to retrieve the cell contents interactively (for further elaboration in pandas, which I use to overcome limitations in Excel). An user-friendly (point-and-click) example to achieve that in VBA would be as follows:
Dim LoopR As Range: Set LoopR = Application.InputBox("Select the range (rows) to iterate over:", "Iteration Range Rows Input", Type:=8)
Which creates a dialog box where the user can select the range manually, and returns it.
I attempted to achieve the same in xlwings with the following:
import xlwings as xw
app = xw.App(add_book=False)
wb = app.books.open('path/to/file.xlsx')
rng = app.api.InputBox("Select the range (rows) to iterate over:", "Iteration Range Rows Input", Type=8)
Which creates the dialog box in the Excel application as expected; however, rng only stores the content (as string) of the top-left cell of the selected range, which in my case defeats the purpose. I haven't found any threads about my specific issue and wouldn't know how to achieve the same using the win23api module.
I think it's possible to achieve what I want in xlwings without having to awkwardly input the range by typing or hardcoding it. Please note that I can't upgrade xlwings (my version is 0.16.0) and therefore can't use the convenient xw.load() function.
I welcome solutions, explanations, or valid alternatives.
P.S.: I've also raised this issue in the xlwings Github repository, where additionally I provided the following system specifications:
- OS Windows Server 2019 (1809)
- Versions of xlwings 0.16.0, Excel for Office 365 MSO (2112), and Python 3.6.9