OpenBI Docs Buy

Excel.Workbook

An Excel workbook's sheets as a navigation table: pick a sheet by its name and take its Data.

Group: Files and documents. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Excel.Workbook(workbook as binary, optional useHeaders as any, optional delayTypes as nullable logical) as table
ParameterTypeDescription
workbookbinaryThe workbook's bytes, from File.Contents, Web.Contents, a blob or any other binary.
useHeadersany
optional
true to make each sheet's first row its headers.
delayTypesnullable logical
optional
Accepted as Power Query writes it; it changes nothing here.

Returns

table. A row per sheet: Name, Data (the sheet's cells as a table), Item, Kind ("Sheet") and Hidden.

Remarks

  • The query Get data writes takes a sheet by its Item and Kind: Source{[Item = "Sales", Kind = "Sheet"]}[Data].
  • A sheet's columns are Column1, Column2 ... unless useHeaders is true. Numbers come as numbers, logicals as logicals, dates and times as datetimes and texts as texts; a cell that holds an Excel error (#N/A) is an error in its cell.
  • A hidden sheet is listed too, with Hidden true.
  • Workbooks in the .xlsx format (Office Open XML) are read. Any binary works, not only a file's: one made in M with Binary.FromText reads the same.

Examples

The sheets of a workbook

Excel.Workbook(File.Contents("C:\Data\book.xlsx"))[[Name], [Item], [Kind], [Hidden]]
NameItemKindHidden
Sales & CostsSales & CostsSheetfalse
HiddenHiddenSheettrue

One sheet, its first row as headers

The sheet's Note column has an Excel error in one cell, so this keeps the other columns.

let
    Source = Excel.Workbook(File.Contents("C:\Data\book.xlsx"), true),
    Sheet = Source{[Item = "Sales & Costs", Kind = "Sheet"]}[Data]
in
    Table.SelectColumns(Sheet, {"Product", "Date", "Amount", "Paid"})
ProductDateAmountPaid
Chair 2024-01-31 00:00:00100.5true
Desk & lamp2024-02-01 12:00:007false
formula textnull107.5null

The texts are as the cells hold them, a trailing space and a line break included; the dates come as datetimes.

File.Contents, Table.PromoteHeaders, Csv.Document, Table.SelectColumns.

Last updated · OpenBI Studio 0.3.79