Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thông số kỹ thuậtNguồndữ liệu
Truy cập vào chế độ cài đặt chung của thông số kỹ thuật nguồn dữ liệu hiện có. Để truy cập vào thông số kỹ thuật nguồn dữ liệu cho một loại nhất định, hãy sử dụng phương thức as...(). Để tạo thông số kỹ thuật nguồn dữ liệu mới, hãy sử dụng SpreadsheetApp.newDataSourceSpec().
Chỉ sử dụng lớp này với dữ liệu được kết nối với cơ sở dữ liệu.
Ví dụ này cho biết cách lấy thông tin từ thông số kỹ thuật của nguồn dữ liệu BigQuery.
Ví dụ này cho thấy cách lấy thông tin từ thông số kỹ thuật của nguồn dữ liệu Looker. Việc sử dụng asLooker() sẽ trả về một đối tượng LookerDataSourceSpec.
// 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();
Phương thức này chỉ áp dụng cho nguồn dữ liệu BigQuery.
// 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();
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\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,["# Class DataSourceSpec\n\nDataSourceSpec\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\n### Methods\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\n### `as``Big``Query()`\n\nGets the spec for BigQuery data source.\n\n#### Return\n\n\n[BigQueryDataSourceSpec](/apps-script/reference/spreadsheet/big-query-data-source-spec) --- The BigQuery data source spec.\n\n*** ** * ** ***\n\n### `as``Looker()`\n\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\n#### Return\n\n\n[LookerDataSourceSpec](/apps-script/reference/spreadsheet/looker-data-source-spec) --- The Looker data source spec.\n\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``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."]]