├── Code.gs
├── README.md
└── Sidebar.html
/Code.gs:
--------------------------------------------------------------------------------
1 | function onOpen() {
2 | SpreadsheetApp.getUi().createMenu('DuckDB').addItem('Run', 'runSQL').addToUi();
3 | }
4 |
5 | function runSQL() {
6 | const html = HtmlService.createHtmlOutputFromFile('Sidebar').setTitle('SQL Runner');
7 | SpreadsheetApp.getUi().showSidebar(html);
8 | }
9 |
10 | function getSelectedQuery() {
11 | const selectedRange = SpreadsheetApp.getActiveRange();
12 | if (!selectedRange) {
13 | throw new Error("Please select a cell containing the SQL query");
14 | }
15 | const query = selectedRange.getValue();
16 | console.log("Selected query:", query);
17 | return query;
18 | }
19 |
20 | function writeResults(data) {
21 | console.log("Writing data to sheet:", data);
22 | const sheet = SpreadsheetApp.getActiveSheet();
23 | if (data && data.length > 0) {
24 | sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
25 | console.log("Data written successfully");
26 | } else {
27 | console.log("No data to write");
28 | }
29 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Google Sheets DuckDB Engine
4 |
5 | This little hack loads DuckDB WASM as a Google Sheets Library to execute, parse and return data.
6 |
7 | > No query data is sent to the extension, google or anywhere. Everything remains local.
8 |
9 | ## Setup
10 | #### Install Extension
11 | - Open a Google Sheets document
12 | - Browse to `Extensions` > `Apps Script`
13 | - At the left of the Apps Script editor, next to `Libraries` click ➕
14 | - In the `Script ID` field, paste `1BacEJir06S0Kojb53TqhX6ECUO1tNZX6SbQoKAPueC_qdZzij3KkBc1M`
15 | - Click `Look up` and choose the latest version
16 | - Click `Add` and Authorize the Library
17 |
18 | 
19 |
20 |
29 |
30 | ### Extension Usage
31 | Type a query in a cell and execute it with DuckDB. Example:
32 | ```
33 | SELECT * FROM 'https://duckdb.org/data/schedule.csv'
34 | ```
35 |
36 |
37 |
38 | ### Todo
39 |
40 | * Add Query Form in the sidebar
41 | * Read Table into DuckDB memory
42 | * Add dropdown with quick examples
43 |
44 |
45 |
46 |
47 | ## DIY Setup
48 | Follow these steps if you'd like to fork and create your own library based on this code. Not needed for testing.
49 |
50 | ### Manual
51 | Browse to Extensions > Apps Script
52 |
53 | 
54 |
55 | Copy the `.gs` + `.html` and Deploy as Library
56 |
57 | 
58 |
59 | > That's it! You can start using your own custom script in Google Sheets
60 |
61 |
--------------------------------------------------------------------------------
/Sidebar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |