// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec().asLooker();if(spec.getType()===SpreadsheetApp.DataSourceType.LOOKER){constlookerSpec=spec.asLooker();Logger.log('Looker instance URL: %s\n',lookerSpec.getInstanceUrl());}
// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec().asLooker();
// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();constnewSpec=spec.copy();
// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();constparameters=spec.getParameters();
// TODO(developer): Replace the URL with your own.constss=SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit',);constspec=ss.getDataSources()[0].getSpec();consttype=spec.getType();
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eDataSourceSpec\u003c/code\u003e provides access to the general settings of an existing database-connected data source.\u003c/p\u003e\n"],["\u003cp\u003eTo access type-specific settings, utilize the \u003ccode\u003eas...()\u003c/code\u003e methods (e.g., \u003ccode\u003easBigQuery()\u003c/code\u003e, \u003ccode\u003easLooker()\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eYou can create a new data source specification using \u003ccode\u003eSpreadsheetApp.newDataSourceSpec()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecopy()\u003c/code\u003e method facilitates creating a \u003ccode\u003eDataSourceSpecBuilder\u003c/code\u003e to modify existing settings.\u003c/p\u003e\n"],["\u003cp\u003eMethods like \u003ccode\u003egetParameters()\u003c/code\u003e and \u003ccode\u003egetType()\u003c/code\u003e allow retrieval of data source parameters and type respectively.\u003c/p\u003e\n"]]],["`DataSourceSpec` accesses settings of existing data sources connected to databases. Use `as...()` to access specific types, like `asBigQuery()` or `asLooker()`. Key actions include: retrieving data source type with `getType()`, fetching parameters via `getParameters()`, and creating a modifiable copy using `copy()`. For example, retrieve BigQuery project ID and raw query string, or get a Looker instance URL. This class can not be used with new data source, use `SpreadsheetApp.newDataSourceSpec()` instead.\n"],null,["DataSourceSpec\n\nAccess the general settings of an existing data source spec. To access data source spec for\ncertain type, use `as...()` method. To create a new data source spec, use [SpreadsheetApp.newDataSourceSpec()](/apps-script/reference/spreadsheet/spreadsheet-app#newDataSourceSpec()).\n\n\n**Only use this class with data that's connected to a database.**\n\n\nThis example shows how to get information from a BigQuery data source spec.\n\n```javascript\nconst dataSourceTable = SpreadsheetApp.getActive()\n .getSheetByName('Data Sheet 1')\n .getDataSourceTables()[0];\nconst spec = dataSourceTable.getDataSource().getSpec();\nif (spec.getType() === SpreadsheetApp.DataSourceType.BIGQUERY) {\n const bqSpec = spec.asBigQuery();\n Logger.log('Project ID: %s\\n', bqSpec.getProjectId());\n Logger.log('Raw query string: %s\\n', bqSpec.getRawQuery());\n}\n```\n\nThis example shows how to get information from a Looker data source spec. Using `as``Looker()` returns a [LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) object.\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().asLooker();\n\nif (spec.getType() === SpreadsheetApp.DataSourceType.LOOKER) {\n const lookerSpec = spec.asLooker();\n Logger.log('Looker instance URL: %s\\n', lookerSpec.getInstanceUrl());\n}\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|-------------------------------------|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|\n| [asBigQuery()](#asBigQuery()) | [BigQueryDataSourceSpec](/apps-script/reference/spreadsheet/big-query-data-source-spec) | Gets the spec for BigQuery data source. |\n| [asLooker()](#asLooker()) | [LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) | Gets the spec for Looker data source. |\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| [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`as``Big``Query()` \nGets the spec for BigQuery data source.\n\nReturn\n\n\n[BigQueryDataSourceSpec](/apps-script/reference/spreadsheet/big-query-data-source-spec) --- The BigQuery data source spec.\n\n*** ** * ** ***\n\n`as``Looker()` \nGets the spec for Looker 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().asLooker();\n```\n\nReturn\n\n\n[LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) --- The Looker data source spec.\n\n*** ** * ** ***\n\n`copy()` \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\nReturn\n\n\n[DataSourceSpecBuilder](/apps-script/reference/spreadsheet/data-source-spec-builder) --- The builder.\n\n*** ** * ** ***\n\n`get``Parameters()` \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\nReturn\n\n\n[DataSourceParameter[]](/apps-script/reference/spreadsheet/data-source-parameter) --- The parameter list.\n\n*** ** * ** ***\n\n`get``Type()` \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\nReturn\n\n\n[DataSourceType](/apps-script/reference/spreadsheet/data-source-type) --- The data source type."]]