const UI = SpreadsheetApp.getUi();
const WORKBOOK = SpreadsheetApp.getActive();
+const FILE_ID = PropertiesService.getScriptProperties().getProperty('FILE_ID');
+
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('SQLite')
*/
const sheets = WORKBOOK.getSheets();
- const fileId = '1xUrGGbaQLVRnytUKtnINAxzild0PBeJZ'; // Google Drive file ID to store the final SQL query
/** Construct SQL for creating the database */
let query = `-- This query was generated by sheets-db
// URL to download the file:
// https://drive.google.com/u/0/uc?id=1xUrGGbaQLVRnytUKtnINAxzild0PBeJZ&export=download
- DriveApp.getFileById(fileId).setContent(query);
+ DriveApp.getFileById(FILE_ID).setContent(query);
- UI.alert('Success!', `Query generated! Download here: https://drive.google.com/u/0/uc?id=${fileId}&export=download`, ui.ButtonSet.OK);
+ UI.alert('Success!', `Query generated! Download here: https://drive.google.com/u/0/uc?id=${FILE_ID}&export=download`, ui.ButtonSet.OK);
}
3. Create a new Google Sheet or create a copy of the [demo Google Sheet](https://docs.google.com/spreadsheets/d/1pY-0oDh4pI8NffZQwN-AkpfJdot7bmlM9nky7w150UY/edit?usp=sharing).
4. Go to Tools > Script Editor to create a new Google Apps Script (GAS) project. The GAS project is automatically attached to the Google Sheet.
5. Copy `Code.gs` into the GAS project and save. If you copied the demo Google Sheet, this code should already be there.
-6. **(IMPORTANT)** In `Code.gs`, update the hardcoded constant `fileId` to the file ID noted in Step 2.
+6. **(IMPORTANT)** In `Code.gs`, there is a reference to a [Google Apps Script property](https://developers.google.com/apps-script/guides/properties) (environment variable) named `FILE_ID`. Use the GAS user interface to set `FILE_ID` to the file ID noted in Step 2.
# Usage