API Reference

Cmdlet

Import-OfficeExcel

Aliases: ExcelImport
Namespace PSWriteOffice
Aliases
ExcelImport
Inputs
System.String System.Uri OfficeIMO.Excel.ExcelDocument System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Outputs
System.Object

Imports rows from an Excel workbook as PowerShell objects.

Remarks

Provides a fast PowerShell read command over the OfficeIMO reader pipeline.

Examples

Authored help example

Import worksheet rows and filter pending items.

PS>


$rows = Import-OfficeExcel -Path .\Report.xlsx -WorksheetName Data -NumericAsDecimal
            $rows |
                Where-Object Status -eq 'Pending' |
                Export-Csv -Path .\PendingRows.csv -NoTypeInformation
        

Reads the used range on the Data worksheet, emits PSCustomObjects, and filters them in PowerShell.

Import every worksheet and keep the source sheet name.

PS>


$rows = Import-OfficeExcel -Path .\Workbook.xlsx -AllSheets
            $rows | Group-Object WorksheetName
        

Reads the used range from each worksheet and adds a WorksheetName property to each emitted row.

Import a worksheet by column.

PS>


Import-OfficeExcel -Path .\Workbook.xlsx -WorksheetName Metrics -ByColumn |
                Where-Object ColumnName -eq 'Revenue' |
                Select-Object -ExpandProperty Values
        

Returns one object per column with the column name, 1-based column index, and the column values as an array.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.

Syntax

Import-OfficeExcel [-AllSheets] [-AsDataReader] [-AsDataTable] [-AsHashtable] [-ByColumn] [-ChunkRows <Int32>] [-CultureName <String>] [-EndColumn <Nullable`1>] [-EndRow <Nullable`1>] [-FormulaMode <CachedValue|FormulaText>] [-NoHeader] [-NumericAsDecimal] -Path <String> [-Range <String>] [-SchemaSampleSize <Int32>] [-SheetIndex <Nullable`1>] [-StartColumn <Nullable`1>] [-StartRow <Nullable`1>] [-WorksheetName <String>] [<CommonParameters>]
#
Parameter set: Path

Parameters

AllSheets SwitchParameter optionalposition: namedpipeline: False
Import all worksheets. Each emitted row or column includes WorksheetName.
AsDataReader SwitchParameter optionalposition: namedpipeline: False
Emit a forward-only IDataReader for database bulk-copy workflows.
AsDataTable SwitchParameter optionalposition: namedpipeline: False
Emit a DataTable instead of enumerating row objects.
AsHashtable SwitchParameter optionalposition: namedpipeline: False
Emit rows as hashtables instead of PSCustomObjects.
ByColumn SwitchParameter optionalposition: namedpipeline: False
Emit one object per column with ColumnName, ColumnIndex, and Values instead of row objects.
ChunkRows Int32 optionalposition: namedpipeline: False
Worksheet row count requested from each streaming chunk when -AsDataReader is used.
CultureName String optionalposition: namedpipeline: False
Culture used when parsing numbers and dates stored as text.
EndColumn Nullable`1 optionalposition: namedpipeline: False
Ending column for an explicit rectangular range.
EndRow Nullable`1 optionalposition: namedpipeline: False
Ending row for an explicit rectangular range.
FormulaMode String optionalposition: namedpipeline: Falsevalues: 2
Formula read mode. CachedValue returns workbook cached results; FormulaText returns formula expressions when present.
Possible values: CachedValue, FormulaText
NoHeader SwitchParameter optionalposition: namedpipeline: False
Treat all rows as data and generate column names instead of using the first row as headers.
NumericAsDecimal SwitchParameter optionalposition: namedpipeline: False
Prefer decimals instead of doubles for numeric values.
Path String requiredposition: 0pipeline: True (ByPropertyName)aliases: FilePath, FullName, InputPath
Workbook path to import.
Range String optionalposition: namedpipeline: True (ByPropertyName)
Optional A1 range to read. When omitted, the used range is imported.
SchemaSampleSize Int32 optionalposition: namedpipeline: False
Maximum row count inspected when -AsDataReader infers the reader schema.
SheetIndex Nullable`1 optionalposition: namedpipeline: True (ByPropertyName)
Zero-based worksheet index to read.
StartColumn Nullable`1 optionalposition: namedpipeline: False
Starting column for an explicit rectangular range.
StartRow Nullable`1 optionalposition: namedpipeline: False
Starting row for an explicit rectangular range.
WorksheetName String optionalposition: namedpipeline: True (ByPropertyName)aliases: Sheet
Worksheet name to read; defaults to the first sheet.

Outputs

System.Object

Import-OfficeExcel [-AllowHttp] [-AllSheets] [-AsDataReader] [-AsDataTable] [-AsHashtable] [-ByColumn] [-ChunkRows <Int32>] [-CultureName <String>] [-EndColumn <Nullable`1>] [-EndRow <Nullable`1>] [-FormulaMode <CachedValue|FormulaText>] [-NoHeader] [-NumericAsDecimal] [-Range <String>] [-SchemaSampleSize <Int32>] [-SheetIndex <Nullable`1>] [-StartColumn <Nullable`1>] [-StartRow <Nullable`1>] -Uri <Uri> [-WorksheetName <String>] [<CommonParameters>]
#
Parameter set: Uri

Parameters

AllowHttp SwitchParameter optionalposition: namedpipeline: False
Allow HTTP workbook downloads in addition to HTTPS.
AllSheets SwitchParameter optionalposition: namedpipeline: False
Import all worksheets. Each emitted row or column includes WorksheetName.
AsDataReader SwitchParameter optionalposition: namedpipeline: False
Emit a forward-only IDataReader for database bulk-copy workflows.
AsDataTable SwitchParameter optionalposition: namedpipeline: False
Emit a DataTable instead of enumerating row objects.
AsHashtable SwitchParameter optionalposition: namedpipeline: False
Emit rows as hashtables instead of PSCustomObjects.
ByColumn SwitchParameter optionalposition: namedpipeline: False
Emit one object per column with ColumnName, ColumnIndex, and Values instead of row objects.
ChunkRows Int32 optionalposition: namedpipeline: False
Worksheet row count requested from each streaming chunk when -AsDataReader is used.
CultureName String optionalposition: namedpipeline: False
Culture used when parsing numbers and dates stored as text.
EndColumn Nullable`1 optionalposition: namedpipeline: False
Ending column for an explicit rectangular range.
EndRow Nullable`1 optionalposition: namedpipeline: False
Ending row for an explicit rectangular range.
FormulaMode String optionalposition: namedpipeline: Falsevalues: 2
Formula read mode. CachedValue returns workbook cached results; FormulaText returns formula expressions when present.
Possible values: CachedValue, FormulaText
NoHeader SwitchParameter optionalposition: namedpipeline: False
Treat all rows as data and generate column names instead of using the first row as headers.
NumericAsDecimal SwitchParameter optionalposition: namedpipeline: False
Prefer decimals instead of doubles for numeric values.
Range String optionalposition: namedpipeline: True (ByPropertyName)
Optional A1 range to read. When omitted, the used range is imported.
SchemaSampleSize Int32 optionalposition: namedpipeline: False
Maximum row count inspected when -AsDataReader infers the reader schema.
SheetIndex Nullable`1 optionalposition: namedpipeline: True (ByPropertyName)
Zero-based worksheet index to read.
StartColumn Nullable`1 optionalposition: namedpipeline: False
Starting column for an explicit rectangular range.
StartRow Nullable`1 optionalposition: namedpipeline: False
Starting row for an explicit rectangular range.
Uri Uri requiredposition: 0pipeline: True (ByPropertyName)aliases: Url
Remote workbook URI to import.
WorksheetName String optionalposition: namedpipeline: True (ByPropertyName)aliases: Sheet
Worksheet name to read; defaults to the first sheet.

Outputs

System.Object

Import-OfficeExcel [-AllSheets] [-AsDataReader] [-AsDataTable] [-AsHashtable] [-ByColumn] [-ChunkRows <Int32>] [-CultureName <String>] -Document <ExcelDocument> [-EndColumn <Nullable`1>] [-EndRow <Nullable`1>] [-FormulaMode <CachedValue|FormulaText>] [-NoHeader] [-NumericAsDecimal] [-Range <String>] [-SchemaSampleSize <Int32>] [-SheetIndex <Nullable`1>] [-StartColumn <Nullable`1>] [-StartRow <Nullable`1>] [-WorksheetName <String>] [<CommonParameters>]
#
Parameter set: Document

Parameters

AllSheets SwitchParameter optionalposition: namedpipeline: False
Import all worksheets. Each emitted row or column includes WorksheetName.
AsDataReader SwitchParameter optionalposition: namedpipeline: False
Emit a forward-only IDataReader for database bulk-copy workflows.
AsDataTable SwitchParameter optionalposition: namedpipeline: False
Emit a DataTable instead of enumerating row objects.
AsHashtable SwitchParameter optionalposition: namedpipeline: False
Emit rows as hashtables instead of PSCustomObjects.
ByColumn SwitchParameter optionalposition: namedpipeline: False
Emit one object per column with ColumnName, ColumnIndex, and Values instead of row objects.
ChunkRows Int32 optionalposition: namedpipeline: False
Worksheet row count requested from each streaming chunk when -AsDataReader is used.
CultureName String optionalposition: namedpipeline: False
Culture used when parsing numbers and dates stored as text.
Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Workbook document to import from.
EndColumn Nullable`1 optionalposition: namedpipeline: False
Ending column for an explicit rectangular range.
EndRow Nullable`1 optionalposition: namedpipeline: False
Ending row for an explicit rectangular range.
FormulaMode String optionalposition: namedpipeline: Falsevalues: 2
Formula read mode. CachedValue returns workbook cached results; FormulaText returns formula expressions when present.
Possible values: CachedValue, FormulaText
NoHeader SwitchParameter optionalposition: namedpipeline: False
Treat all rows as data and generate column names instead of using the first row as headers.
NumericAsDecimal SwitchParameter optionalposition: namedpipeline: False
Prefer decimals instead of doubles for numeric values.
Range String optionalposition: namedpipeline: True (ByPropertyName)
Optional A1 range to read. When omitted, the used range is imported.
SchemaSampleSize Int32 optionalposition: namedpipeline: False
Maximum row count inspected when -AsDataReader infers the reader schema.
SheetIndex Nullable`1 optionalposition: namedpipeline: True (ByPropertyName)
Zero-based worksheet index to read.
StartColumn Nullable`1 optionalposition: namedpipeline: False
Starting column for an explicit rectangular range.
StartRow Nullable`1 optionalposition: namedpipeline: False
Starting row for an explicit rectangular range.
WorksheetName String optionalposition: namedpipeline: True (ByPropertyName)aliases: Sheet
Worksheet name to read; defaults to the first sheet.

Outputs

System.Object