Bru*_*cio 7 google-sheets node.js google-sheets-api
我sheets.spreadsheets.values.get用来获取电子表格中的信息,但包含图像的单元格显示空字符串值。
我尝试使用values:userEnteredValue作为请求的参数(如这个问题Retrieve images in cells using Google Sheets API 所示),但这不起作用。
sheets.spreadsheets.values.get({
spreadsheetId: 'XXX',
range: 'firstSheet!A1:E10',
key: "XXXX"
//values: 'userEnteredValue'
}
Run Code Online (Sandbox Code Playgroud)
编辑:我意识到我的问题之一是我spreadsheets.values.get在应该使用spreadsheets.get. 我已经改变了这个,但我仍然无法获得网址
包含文本的单元格具有userEnteredValue属性,但包含图像的单元格没有。
=image("https://www.google.com/images/srpr/logo3w.png")单元格中检索 URL 。sheets.spreadsheets.values.get()。如果我的理解是正确的,这个修改怎么样?
=image("https://www.google.com/images/srpr/logo3w.png")作为公式放入单元格。因此,为了检索公式,请使用valueRenderOption: "FORMULA".此修改后的脚本假设将=image("https://www.google.com/images/srpr/logo3w.png")其放在工作表名称“Sheet1”的单元格“A1”中。
sheets.spreadsheets.values.get(
{
spreadsheetId: "###",
range: "Sheet1!A1",
valueRenderOption: "FORMULA"
},
function(err, res) {
if (err) {
console.log(err);
return;
}
const url = res.data.values[0][0].match(/https?:\/\/[\w\S][^"]+/)[0];
console.log(url);
}
);
Run Code Online (Sandbox Code Playgroud)
https://www.google.com/images/srpr/logo3w.png
Run Code Online (Sandbox Code Playgroud)
如果我误解了您的问题并且这不是您想要的结果,我深表歉意。
如果我的理解是正确的,不幸的是,在当前阶段,当通过“电子表格中的插入选项”将图像从 URL 插入到单元格中时,Sheets API 和电子表格服务无法检索图像的 URL。此外,当通过“电子表格中的 INSERT 选项”从 URL 将图像插入到工作表中时,Sheets API 和电子表格服务无法检索图像的 URL。我为这种情况道歉。