How to Run SQL-Style Queries on Excel Workbook Data Using Office Scripts
Question details
The user is trying to perform complex relational SQL-style queries directly on workbook data using Excel Office Scripts but is unable to find a built-in ADO-style SQL engine.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Executing advanced data manipulations, complex table joins, and direct column comparisons within an Excel workbook environment using automated scripts.
- Observed behavior
- Excel Office Scripts do not provide a native ADO-style SQL engine, making it difficult to run relational queries such as complex joins or comparing values across different columns.
Assess the complexity of your data manipulation needs. While standard TypeScript can handle basic filtering in Office Scripts, complex relational joins are better handled by Power Query or by exporting your data to a dedicated SQL database.
Use Power Query for Advanced Relational Transformations
Since Office Scripts lack an SQL engine, Power Query is the most powerful native Excel alternative for joining tables, filtering records, and merging datasets without writing complex code.
Power Query operates similarly to a relational database engine. It provides a visual interface for transforming data, allowing you to perform inner, outer, and anti-joins just like you would with SQL.
Go to the 'Data' tab on the Excel ribbon, click 'Get Data', and select your data source (e.g., 'From Table/Range' if the data is already in your workbook).
In the Power Query Editor, click 'Merge Queries' on the Home tab to combine two tables based on a matching column, replicating a SQL JOIN operation.
Use the column dropdowns to filter data or add custom conditional columns to replicate SQL WHERE and CASE statements.
Click 'Close & Load' to output your fully transformed and joined dataset into a new Excel worksheet.

Migrate Data to a Cloud Database for Native SQL Execution
If your application requires strict SQL syntax and complex database architecture, moving the workbook data to a cloud database is the most scalable approach.
Simulate SQL Filtering using TypeScript in Office Scripts
For straightforward data extraction and comparisons, you can use native TypeScript array methods within Office Scripts to map and filter workbook data.
Handle Complex Spreadsheet Data and Macros with WPS Office
If modern Excel Office Scripts fall short because they lack traditional ADO SQL connectivity, WPS Office provides a robust, highly compatible environment. WPS Spreadsheets supports classic VBA macros natively, allowing you to run traditional ADO database connections and SQL queries directly on your workbook without complex workarounds.
- 1. Download and Install: Download WPS Office for free from the official website and follow the quick installation prompts.
- 2. Open Your Workbook: Launch WPS Spreadsheets and seamlessly open your existing .xlsx or .xlsm files.
- 3. Access Macro Tools: Navigate to the Developer tab to access powerful Macro and VBA tools for advanced SQL querying.

Frequently Asked Questions
Does Excel Office Scripts support ADO connections?
No. Office Scripts run in a secure cloud-based environment using TypeScript and do not support the legacy ActiveX Data Objects (ADO) library required for native SQL queries. For ADO support, traditional VBA is required.
Can I query an Excel table using SQL without external tools?
Natively, Excel does not have an internal SQL engine that accepts standard SQL text queries directly on cells. However, Power Query uses the M formula language to accomplish the exact same relational tasks (joins, groupings, filtering) via a graphical interface.
Is Power Query better than Office Scripts for data joins?
Yes. Power Query is specifically designed for complex data shaping, merging, and relational joins. Office Scripts are better suited for automating repetitive formatting tasks and triggering custom workflows, rather than processing complex relational datasets.
How do I perform a VLOOKUP equivalent in Office Scripts?
You can simulate a VLOOKUP in Office Scripts by fetching the range values into an array and using the TypeScript 'find()' or 'filter()' methods to locate matching records across different rows.




