Description: Executes a query, exports its result set to Excel and optionally opens or downloads the generated file.
Calling convention: CIP_SQLToExcel("DBName": String, "SQLStatement": String, ["FilePath": String = ""], [OpenExcelFile: Boolean = True]): Variant
Parameters:
DBName: connection name; an empty String uses the current connection.
SQLStatement: query text. Named parameters are resolved from DBForm entries, parser variables, runtime variables or user-script locals.
FilePath: optional target; an empty desktop path opens a save dialog.
OpenExcelFile: opens the file on desktop or starts a download on web.
Returns: Generated file path, or Variant NULL for cancellation, an empty result set or an incomplete request. SQL and export errors raise exceptions.
Availability: Default; requires database and file-system access. Only connections visible to the current user are accepted.
Example:
FileName := CIP_SQLToExcel("", "SELECT * FROM ORDERS WHERE STATUS=:Status", "C:\Exports\orders.xlsx", False);