[Fixed]Spreadsheet: how to set cell knowing its alias?

Need help, or want to share a macro? Post here!
User avatar
DeepSOIC
Posts: 7015
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

[Fixed]Spreadsheet: how to set cell knowing its alias?

Postby DeepSOIC » Sun Jan 10, 2016 11:53 pm

Hi!
I can't find a way to set cell of a spreadsheed from python, given its alias name as a string. I tried:

Code: Select all

>>> sp.set("mycell","8")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: Invalid cell specifier.
Doesn't work. I also tried to extract cell address given the alias, and to find the table of correspondence address<->alias. So far, not found anything directly usable.

I can, in theory, extract the addres<->alias from .cells.Content, which outputs an XML string. But I don't really want to mess with parsing XML for just this.
wmayer
Site Admin
Posts: 14869
Joined: Thu Feb 19, 2009 10:32 am

Re: Spreadsheet: how to set cell knowing its alias?

Postby wmayer » Mon Jan 11, 2016 9:51 am

Would be good to have two additional methods: getAlias to get the alias name of a cell and getCellFromAlias to get the cell name of an alias.

Btw, I discovered two bugs in the Spreadsheet module:
  • When you set an alias per GUI then this alias name appears as attribute in the Python binding. If you set the alias from Python then this attribute doesn't appear.
  • It's possible that two different cells have the same alias name. If you access the alias then the value of the last cell for which the alias is set is returned. But when you overwrite the alias of any of the previous cells the old alias is completely removed. So, it must be avoided to set the same alias to multiple cells.
eivindkvedalen
Posts: 598
Joined: Tue Jan 29, 2013 10:35 pm

Re: Spreadsheet: how to set cell knowing its alias?

Postby eivindkvedalen » Sat Jan 16, 2016 9:53 am

wmayer wrote:Would be good to have two additional methods: getAlias to get the alias name of a cell and getCellFromAlias to get the cell name of an alias.
I have this in my branch at: https://github.com/eivindkv/free-cad-co ... s_20160115
wmayer wrote:
  • When you set an alias per GUI then this alias name appears as attribute in the Python binding. If you set the alias from Python then this attribute doesn't appear.
You have to invoke recompute before it appears, maybe you missed that?
wmayer wrote:[*]It's possible that two different cells have the same alias name. If you access the alias then the value of the last cell for which the alias is set is returned. But when you overwrite the alias of any of the previous cells the old alias is completely removed. So, it must be avoided to set the same alias to multiple cells.[/list]
Fixed in the branch above. Please test and see if this solves your problems, and I'll make a pull request.

Eivind
wmayer
Site Admin
Posts: 14869
Joined: Thu Feb 19, 2009 10:32 am

Re: Spreadsheet: how to set cell knowing its alias?

Postby wmayer » Sat Jan 16, 2016 4:01 pm

You have to invoke recompute before it appears, maybe you missed that?
Yes, I missed this. Thanks!
wmayer
Site Admin
Posts: 14869
Joined: Thu Feb 19, 2009 10:32 am

Re: Spreadsheet: how to set cell knowing its alias?

Postby wmayer » Tue Jan 26, 2016 11:14 am

I can't find a way to set cell of a spreadsheed from python, given its alias name as a string. I tried:
This is now implemented in master.
User avatar
DeepSOIC
Posts: 7015
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Spreadsheet: how to set cell knowing its alias?

Postby DeepSOIC » Tue Jan 26, 2016 11:25 am

Thanks Eivind and Werner!! Awesome!