I'm using https://www.npmjs.com/package/googleapis to insert data. One of my cells should contain multiple links, let's say
https://foo
https://bar
This is easy to do manually and I can query manually antered data and see the formatting. With this:
const res = await sheets.spreadsheets.get({
spreadsheetId,
ranges: ['Intro!A1'],
includeGridData: true
})
I can see the data formatting in res; screenshot below of the data from debugging. Circled in red is the value of the cell, underlined in blue is the first link defined in textFormatRuns.
This is what I tried to test formatting. This successfully writes the stringValue, but the textFormatRuns does nothing
{
userEnteredValue: {
stringValue: "ABCDEFGHIJKLMNOP\nabcdefghijklmnop"
},
textFormatRuns: [
{
format: { bold: true, underline: true, link: { uri: "https://ddg.gg" } }
},
{
format:{}, startIndex: 9,
}
]
}
In the end the solution was that my
UpdateCellsRequestcontained this part:fields: 'userEnteredValue'which was somehow blocking the formatting update. This is very strange to me.Here is a final proof of concept request that actually works to insert text into a cell and format parts of the cell (typescript):
Here is the result; note the bold formatting and clickable link