简体   繁体   中英

Python OpenPyXL, Assign a Value to a Range

I'm using Python and openpyxl to work with an Excel Spreadsheet and want to assign a value to a named range (Of a single cell) on a sheet. What's the syntax? For instance, if the sheet is, "Dog," and the single celled range is "dog_name?"

I was expecting something like wb["Dog"]["dog_name"] = "Snoopy" but, that's a fail.

Thanks for the help!

This is an example of syntax that I got to work:

wb["Dog"][wb.defined_names["dog_name"].value[-4:]] = "Snoopy"

It strips out the cell address of the range to use as the address for the assignment. Seems inelegant to me so, please post alternatives.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM