microsoft / python-in-excel

Python in Microsoft Excel
MIT License
490 stars 31 forks source link

Allow string references to be passed to ref argument in xl method #24

Open ncalm opened 10 months ago

ncalm commented 10 months ago

Passing a string of a spreadsheet range address to the xl method causes "NameError: name 'xl' is not defined"

It would be useful to be able to pass Names, connection names, range addresses etc as strings to the xl method.

image

salabim commented 10 months ago

I'm afraid this is rather fundamental as the Excel engine can automatically update row and column numbers when you insert or delete rows/columns. On the other hand, $B$3 should never be a problem. Let's hope this will be adopted in the next release.

Bobby-Miller commented 9 months ago

In the same vein, adding a tab index optional kwarg would be very helpful: image

WillemWannenburg commented 8 months ago

Is this fundamentally even possible? My question (and I think this question as well) is: is it possible to write to the xl() in a cell other than the one the python script is in? It's easy to read from xl() : a = xl("A1") But is it possible to write: a = 1 xl("B2") == a

ncalm commented 8 months ago

Is this fundamentally even possible? My question (and I think this question as well) is: is it possible to write to the xl() in a cell other than the one the python script is in? It's easy to read from xl() : a = xl("A1") But is it possible to write: a = 1 xl("B2") == a

xl is a method that converts an Excel range, name or Power Query connection to some Python object. By default this is a DataFrame for Excel arrays of more than one cell, and a scalar for single-cell arrays, but it can be changed. I made a video about how to do that.

xl("B2") doesn't represent a cell. Rather, it applies the conversion to whatever data are in B2.

What I'm suggesting with this request is a Python in Excel analog to the INDIRECT function.

salabim commented 8 months ago

@ncalm What I'm suggesting with this request is a Python in Excel analog to the INDIRECT function. That is indeed what we need!