I want to insert in Google sheets cell text with hyperlink:
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
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