Class LookerDataSourceSpec
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Looker数据源规范
DataSourceSpec
,用于专门访问现有的 Looker 数据源规范。如需创建新的“数据源规范”,请使用 SpreadsheetApp.newDataSourceSpec()
。
以下示例展示了如何从仅包含一个 Looker 连接的工作表中获取 Looker 数据源规范。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
详细文档
copy()
根据此数据源的设置创建 DataSourceSpecBuilder
。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const spec = ss.getDataSources()[0].getSpec();
const newSpec = spec.copy();
返回
DataSourceSpecBuilder
- 构建器。
getExploreName()
获取模型中的 Looker 探索的名称。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const exploreName = lookerDataSourceSpec.getExploreName();
Logger.log(exploreName);
返回
String
- Looker 探索的名称。
getInstanceUrl()
获取 Looker 实例的网址。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const instanceUrl = lookerDataSourceSpec.getInstanceUrl();
Logger.log(instanceUrl);
返回
String
- Looker 实例的网址。
getModelName()
获取实例中 Looker 模型的名称。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();
const modelName = lookerDataSourceSpec.getModelName();
Logger.log(modelName);
返回
String
- Looker 模型的名称。
getParameters()
获取数据源的参数。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const spec = ss.getDataSources()[0].getSpec();
const parameters = spec.getParameters();
此方法仅适用于 BigQuery 数据源。
返回
DataSourceParameter[]
- 参数列表。
getType()
获取数据源的类型。
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc123456/edit',
);
const spec = ss.getDataSources()[0].getSpec();
const type = spec.getType();
返回
DataSourceType
- 数据源类型。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eLookerDataSourceSpec\u003c/code\u003e enables access to existing Looker data source specifications within Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eTo create new data source specifications, use \u003ccode\u003eSpreadsheetApp.newDataSourceSpec()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve details such as explore name, instance URL, and model name from a \u003ccode\u003eLookerDataSourceSpec\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eSeveral methods, including \u003ccode\u003ecopy()\u003c/code\u003e, \u003ccode\u003egetExploreName()\u003c/code\u003e, \u003ccode\u003egetInstanceUrl()\u003c/code\u003e, \u003ccode\u003egetModelName()\u003c/code\u003e, \u003ccode\u003egetParameters()\u003c/code\u003e, and \u003ccode\u003egetType()\u003c/code\u003e, are available for interacting with Looker data source specifications.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetParameters()\u003c/code\u003e method is specific to BigQuery data sources and retrieves their parameters.\u003c/p\u003e\n"]]],["The `LookerDataSourceSpec` accesses existing Looker data sources. Key actions include retrieving data source details via methods: `getExploreName()` gets the Looker explore name, `getInstanceUrl()` gets the Looker instance URL, and `getModelName()` gets the Looker model name. `getParameters()` retrieves data source parameters (available only for BigQuery), and `getType()` gets the data source type. The `copy()` method creates a `DataSourceSpecBuilder` based on current settings. You can retrieve the looker data source by using `getDataSources()[0].getSpec().asLooker()`.\n"],null,["# Class LookerDataSourceSpec\n\nLookerDataSourceSpec\n\nA [DataSourceSpec](/apps-script/reference/spreadsheet/data-source-spec) which is used to access specifically the existing Looker data source\nspecifications. To create a new data source specification, use [SpreadsheetApp.newDataSourceSpec()](/apps-script/reference/spreadsheet/spreadsheet-app#newDataSourceSpec()).\n\nThis example shows how you can get the Looker data source spec from a sheet which has just one\nLooker connection.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\n\nconst lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|\n| [copy()](#copy()) | [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) | Creates a [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) based on this data source's settings. |\n| [getExploreName()](#getExploreName()) | `String` | Gets the name of the Looker explore in the model. |\n| [getInstanceUrl()](#getInstanceUrl()) | `String` | Gets the URL of the Looker instance. |\n| [getModelName()](#getModelName()) | `String` | Gets the name of the Looker model in the instance. |\n| [getParameters()](#getParameters()) | [DataSourceParameter[]](/apps-script/reference/spreadsheet/data-source-parameter) | Gets the parameters of the data source. |\n| [getType()](#getType()) | [DataSourceType](/apps-script/reference/spreadsheet/data-source-type) | Gets the type of the data source. |\n\nDetailed documentation\n----------------------\n\n### `copy()`\n\nCreates a [DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) based on this data source's settings.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\n\nconst newSpec = spec.copy();\n```\n\n#### Return\n\n\n[DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) --- The builder.\n\n*** ** * ** ***\n\n### `get``Explore``Name()`\n\nGets the name of the Looker explore in the model.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\n\nconst lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();\nconst exploreName = lookerDataSourceSpec.getExploreName();\nLogger.log(exploreName);\n```\n\n#### Return\n\n\n`String` --- The name of the Looker explore.\n\n*** ** * ** ***\n\n### `get``Instance``Url()`\n\nGets the URL of the Looker instance.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\n\nconst lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();\nconst instanceUrl = lookerDataSourceSpec.getInstanceUrl();\nLogger.log(instanceUrl);\n```\n\n#### Return\n\n\n`String` --- The URL of the Looker instance.\n\n*** ** * ** ***\n\n### `get``Model``Name()`\n\nGets the name of the Looker model in the instance.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\n\nconst lookerDataSourceSpec = ss.getDataSources()[0].getSpec().asLooker();\nconst modelName = lookerDataSourceSpec.getModelName();\nLogger.log(modelName);\n```\n\n#### Return\n\n\n`String` --- The name of the Looker model.\n\n*** ** * ** ***\n\n### `get``Parameters()`\n\nGets the parameters of the data source.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\nconst parameters = spec.getParameters();\n```\n\nThis method is only available for BigQuery data sources.\n\n#### Return\n\n\n[DataSourceParameter[]](/apps-script/reference/spreadsheet/data-source-parameter) --- The parameter list.\n\n*** ** * ** ***\n\n### `get``Type()`\n\nGets the type of the data source.\n\n```javascript\n// TODO(developer): Replace the URL with your own.\nconst ss = SpreadsheetApp.openByUrl(\n 'https://docs.google.com/spreadsheets/d/abc123456/edit',\n);\nconst spec = ss.getDataSources()[0].getSpec();\nconst type = spec.getType();\n```\n\n#### Return\n\n\n[DataSourceType](/apps-script/reference/spreadsheet/data-source-type) --- The data source type."]]