Monday, February 4, 2019

Set http link for text cell in Google Sheets Java Api



I want to insert in Google sheets cell text with hyperlink:



enter image description here



I tried this Java code:



values.add(new CellData()

.setUserEnteredValue(new ExtendedValue()
.setStringValue(get.getTitle())).setHyperlink(get.getUrl())


But I get only text without hyperlink.
How I can implement this?


Answer



In Documentation





A hyperlink this cell points to, if any. This field is read-only. (To set it, use a =HYPERLINK formula in the userEnteredValue.formulaValue field.)




Without formula, api creates cell with hyperlink info, to activate behaviour you need to set formulaValue as =HYPERLINK .



You can forget about the idea above, hyperlink is just a read only field for CellData.



Also you can't set multiple property for an ExtendedValue object it only accepts single property to set.All properties points a value for Cell but only difference is those setters determines the type of cell value (bool, string, formula, number, error), so you can't set multiple value for Single Cell thats why you get the error( (oneof), oneof field 'value' is already set ).



Here is the new code, you can add hyperlink by this way.




new CellData()
.setUserEnteredValue(new ExtendedValue()
.setFormulaValue("=HYPERLINK(\"http://stackoverflow.com\",\"SO label\")"))

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...