Skip to content

workbook.workbookFromQuery ​

Runs a SQL query on a JDBC datasource and returns the results as an Excel workbook, base64-encoded. The sheet starts with the date it was generated, the datasource and the query, followed by the results with a header row.

js
workbook.workbookFromQuery(datasource, query, prompts)

Parameters ​

ParameterTypeDescription
datasourcestringThe JDBC datasource's name.
querystringThe SQL query. Use ? placeholders for values.
promptsstring[]Optional. Values for the ? placeholders, in order.

Returns ​

string | null

The workbook, base64-encoded, or null if it couldn't be created. The reason is written to the process log.

Examples ​

js
const report = workbook.workbookFromQuery("Sales DB", "SELECT * FROM sales");
js
// Email the results of a query
const report = workbook.workbookFromQuery("Sales DB", "SELECT * FROM sales WHERE year = ?", ["2026"]);

new EmailBuilder()
    .to("user@example.com")
    .subject("Sales 2026")
    .body("The report is attached.")
    .attachBase64("sales.xlsx", report)
    .send();