如何在 Ballerina 中使用 Google Sheets 连接器创建超链接?

问题描述 投票:0回答:1

我想为谷歌工作表的单元格内容“插入链接”。在《芭蕾舞女演员》中我该如何做到这一点?我在文档中找不到任何示例。

我尝试在 Ballerina By Examples 中搜索这样的例子。但找不到任何。但是,我能够使用 google.sheets 连接器成功编辑单元格内的单元格内容。

integration connector ballerina
1个回答
0
投票

要使用 Ballerina 中的 google.sheets 连接器将超链接插入到单元格内容中,您可以使用 setCell 函数并将

valueInputOption
参数指定为
USER_ENTERED
。此设置将该值视为来自 UI 的用户输入,并将其转换为超链接。

这是一个示例代码片段:

import ballerinax/googleapis.sheets;

configurable string token = ?;
configurable string spreadsheetId = ?;
configurable string sheetName = ?;

public function main() returns error? {

    // Initialize the Google Sheets client
    sheets:Client sheetsEp = check new (config = {
        auth: {
            token: token
        }
    });

    // Specify the cell (B2 in this case) where you want to insert the hyperlink
    string cell = "B2";

    // Specify the hyperlink URL that you want to insert into the cell
    string hyperlink = "http://example.com/";

    // Set the hyperlink using the setCell function
    check sheetsEp->setCell(
        spreadsheetId,
        sheetName,
        a1Notation = cell,
        value = hyperlink,
        valueInputOption = "USER_ENTERED"
    );
}

确保添加配置(令牌、电子表格 ID 和工作表名称)以及特定于您的 Google Sheets API 凭据和电子表格的适当值。

有关 setCell 函数和其他选项的更多详细信息,您可以参考 Google Sheets API 官方文档:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/更新

© www.soinside.com 2019 - 2024. All rights reserved.