From 84140d757a30a59eb0161465a4a5ba8c4ceb175b Mon Sep 17 00:00:00 2001 From: jhoneill Date: Sun, 15 Dec 2019 22:36:31 +0000 Subject: [PATCH] #737 #741, #746 & Tests --- ImportExcel.psd1 | 85 ++++---- Public/ConvertFrom-ExcelSheet.ps1 | 54 +++-- Public/Export-ExcelSheet.md | 138 ------------- Public/Export-ExcelSheet.ps1 | 39 ---- Public/New-ConditionalText.ps1 | 29 +-- __tests__/Compare-WorkSheet.tests.ps1 | 11 +- __tests__/ConvertFrom-ExcelSheet.Tests.ps1 | 33 +++ __tests__/First10Races.xlsx | Bin 0 -> 14833 bytes __tests__/ImportExcelTests/Simple.tests.ps1 | 6 +- mdHelp/en/ConvertFrom-ExcelSheet.md | 217 ++++++++++++++++++++ 10 files changed, 346 insertions(+), 266 deletions(-) delete mode 100644 Public/Export-ExcelSheet.md delete mode 100644 Public/Export-ExcelSheet.ps1 create mode 100644 __tests__/ConvertFrom-ExcelSheet.Tests.ps1 create mode 100644 __tests__/First10Races.xlsx create mode 100644 mdHelp/en/ConvertFrom-ExcelSheet.md diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index ec936b9..c42dd17 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -26,38 +26,7 @@ PowerShell module to import/export Excel spreadsheets, without Excel. Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5uoqS92stXioZw-u-ze_NtvSo0k0K0kq '@ - # Minimum version of the Windows PowerShell engine required by this module - # PowerShellVersion = '' - # Name of the Windows PowerShell host required by this module - # PowerShellHostName = '' - - # Minimum version of the Windows PowerShell host required by this module - # PowerShellHostVersion = '' - - # Minimum version of Microsoft .NET Framework required by this module - # DotNetFrameworkVersion = '' - - # Minimum version of the common language runtime (CLR) required by this module - # CLRVersion = '' - - # Processor architecture (None, X86, Amd64) required by this module - # ProcessorArchitecture = '' - - # Modules that must be imported into the global environment prior to importing this module - # RequiredModules = @() - - # Script files (.ps1) that are run in the caller's environment prior to importing this module. - # ScriptsToProcess = @() - - # Type files (.ps1xml) to be loaded when importing this module - # TypesToProcess = @() - - # Format files (.ps1xml) to be loaded when importing this module - # FormatsToProcess = @() - - # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess - # NestedModules = @() # Functions to export from this module FunctionsToExport = @( @@ -125,15 +94,10 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Update-FirstObjectProperties' ) - # Cmdlets to export from this module - #CmdletsToExport = '*' - - # Variables to export from this module - #VariablesToExport = '*' - # Aliases to export from this module AliasesToExport = @( - 'Convert-XlRangeToImage' + 'Convert-XlRangeToImage', + 'Export-ExcelSheet', 'New-ExcelChart', 'Set-Column', 'Set-Format', @@ -141,10 +105,9 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Use-ExcelData' ) - # List of all modules packaged with this module - # ModuleList = @() + # Cmdlets to export from this module + CmdletsToExport = @() - # List of all files packaged with this module FileList = @( '.\EPPlus.dll', '.\Export-charts.ps1', @@ -199,6 +162,46 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 } } + # Minimum version of the Windows PowerShell engine required by this module + # PowerShellVersion = '' + + # Name of the Windows PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the Windows PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module + # CLRVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # Variables to export from this module + #VariablesToExport = '*' + # HelpInfo URI of this module # HelpInfoURI = '' diff --git a/Public/ConvertFrom-ExcelSheet.ps1 b/Public/ConvertFrom-ExcelSheet.ps1 index 2c997af..db054f4 100644 --- a/Public/ConvertFrom-ExcelSheet.ps1 +++ b/Public/ConvertFrom-ExcelSheet.ps1 @@ -1,48 +1,42 @@ function ConvertFrom-ExcelSheet { [CmdletBinding()] - param - ( - [Alias("FullName")] + [Alias("Export-ExcelSheet")] + param ( [Parameter(Mandatory = $true)] - [String] - $Path, - [String] - $OutputPath = '.\', - [String] - $SheetName = "*", - [ValidateSet('ASCII', 'BigEndianUniCode', 'Default', 'OEM', 'UniCode', 'UTF32', 'UTF7', 'UTF8')] - [string] - $Encoding = 'UTF8', - [ValidateSet('.txt', '.log', '.csv')] - [string] - $Extension = '.csv', + [String]$Path, + [String]$OutputPath = '.\', + [String]$SheetName = "*", + [ValidateSet('ASCII', 'BigEndianUniCode','Default','OEM','UniCode','UTF32','UTF7','UTF8')] + [string]$Encoding = 'UTF8', + [ValidateSet('.txt', '.log','.csv')] + [string]$Extension = '.csv', [ValidateSet(';', ',')] - [string] - $Delimiter = ';' + [string]$Delimiter , + $Property = "*", + $ExcludeProperty = @(), + [switch]$Append, + [string[]]$AsText = @() ) $Path = (Resolve-Path $Path).Path - $Stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path, "Open", "Read", "ReadWrite" - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Stream + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path $workbook = $xl.Workbook - $targetSheets = $workbook.Worksheets | Where-Object { $_.Name -like $SheetName } + $targetSheets = $workbook.Worksheets | Where-Object {$_.Name -Like $SheetName} - $params = @{ } + $PSBoundParameters - $params.Remove("OutputPath") - $params.Remove("SheetName") - $params.Remove('Extension') - $params.NoTypeInformation = $true + $csvParams = @{NoTypeInformation = $true} + $PSBoundParameters + foreach ($p in 'OutputPath', 'SheetName', 'Extension', 'Property','ExcludeProperty', 'AsText') { + $csvParams.Remove($p) + } Foreach ($sheet in $targetSheets) { Write-Verbose "Exporting sheet: $($sheet.Name)" - $params.Path = "$OutputPath\$($Sheet.Name)$Extension" + $csvParams.Path = "$OutputPath\$($Sheet.Name)$Extension" - Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params - } + Import-Excel -ExcelPackage $xl -Sheet $($sheet.Name) -AsText:$AsText | + Select-Object -Property $Property | Export-Csv @csvparams + } - $Stream.Close() - $Stream.Dispose() $xl.Dispose() } diff --git a/Public/Export-ExcelSheet.md b/Public/Export-ExcelSheet.md deleted file mode 100644 index 765dea7..0000000 --- a/Public/Export-ExcelSheet.md +++ /dev/null @@ -1,138 +0,0 @@ ---- -external help file: ImportExcel-help.xml -Module Name: ImportExcel -online version: https://github.com/dfinke/ImportExcel -schema: 2.0.0 ---- - -# Export-ExcelSheet - -## SYNOPSIS -{{ Fill in the Synopsis }} - -## SYNTAX - -``` -Export-ExcelSheet [-Path] [[-OutputPath] ] [[-SheetName] ] [[-Encoding] ] [[-Extension] ] [[-Delimiter] ] [] -``` - -## DESCRIPTION -{{ Fill in the Description }} - -## EXAMPLES - -### Example 1 -```powershell -PS C:\> {{ Add example code here }} -``` - -{{ Add example description here }} - -## PARAMETERS - -### -Delimiter -{{ Fill Delimiter Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: -Accepted values: ;, , - -Required: False -Position: 5 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Encoding -{{ Fill Encoding Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: -Accepted values: ASCII, BigEndianUniCode, Default, OEM, UniCode, UTF32, UTF7, UTF8 - -Required: False -Position: 3 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Extension -{{ Fill Extension Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: -Accepted values: .txt, .log, .csv - -Required: False -Position: 4 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -OutputPath -{{ Fill OutputPath Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Path -{{ Fill Path Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -SheetName -{{ Fill SheetName Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### None - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS diff --git a/Public/Export-ExcelSheet.ps1 b/Public/Export-ExcelSheet.ps1 deleted file mode 100644 index 27e8de5..0000000 --- a/Public/Export-ExcelSheet.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -function Export-ExcelSheet { - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [String]$Path, - [String]$OutputPath = '.\', - [String]$SheetName, - [ValidateSet('ASCII', 'BigEndianUniCode','Default','OEM','UniCode','UTF32','UTF7','UTF8')] - [string]$Encoding = 'UTF8', - [ValidateSet('.txt', '.log','.csv')] - [string]$Extension = '.csv', - [ValidateSet(';', ',')] - [string]$Delimiter = ';' - ) - - $Path = (Resolve-Path $Path).Path - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path - $workbook = $xl.Workbook - - $targetSheets = $workbook.Worksheets | Where-Object {$_.Name -Match $SheetName} - - $params = @{} + $PSBoundParameters - $params.Remove("OutputPath") - $params.Remove("SheetName") - $params.Remove('Extension') - $params.NoTypeInformation = $true - - Foreach ($sheet in $targetSheets) - { - Write-Verbose "Exporting sheet: $($sheet.Name)" - - $params.Path = "$OutputPath\$($Sheet.Name)$Extension" - - Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params - } - - $xl.Dispose() -} diff --git a/Public/New-ConditionalText.ps1 b/Public/New-ConditionalText.ps1 index e7e990c..402310c 100644 --- a/Public/New-ConditionalText.ps1 +++ b/Public/New-ConditionalText.ps1 @@ -3,27 +3,28 @@ function New-ConditionalText { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] param( #[Parameter(Mandatory=$true)] - [Alias("ConditionValue")] + [Alias('ConditionValue')] $Text, - [Alias("ForeGroundColor")] + [Alias('ForeGroundColor')] $ConditionalTextColor=[System.Drawing.Color]::DarkRed, $BackgroundColor=[System.Drawing.Color]::LightPink, [String]$Range, [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid, [ValidateSet( - "LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual", - "Equal", "NotEqual", - "Top", "TopPercent", "Bottom", "BottomPercent", - "ContainsText", "NotContainsText", "BeginsWith", "EndsWith", - "ContainsBlanks", "NotContainsBlanks", "ContainsErrors", "NotContainsErrors", - "DuplicateValues", "UniqueValues", - "Tomorrow", "Today", "Yesterday", "Last7Days", - "NextWeek", "ThisWeek", "LastWeek", - "NextMonth", "ThisMonth", "LastMonth", - "AboveAverage", "AboveOrEqualAverage", "BelowAverage", "BelowOrEqualAverage" + 'LessThan', 'LessThanOrEqual', 'GreaterThan', 'GreaterThanOrEqual', + 'Equal', 'NotEqual', + 'Top', 'TopPercent', 'Bottom', 'BottomPercent', + 'ContainsText', 'NotContainsText', 'BeginsWith', 'EndsWith', + 'ContainsBlanks', 'NotContainsBlanks', 'ContainsErrors', 'NotContainsErrors', + 'DuplicateValues', 'UniqueValues', + 'Tomorrow', 'Today', 'Yesterday', 'Last7Days', + 'NextWeek', 'ThisWeek', 'LastWeek', + 'NextMonth', 'ThisMonth', 'LastMonth', + 'AboveAverage', 'AboveOrEqualAverage', 'BelowAverage', 'BelowOrEqualAverage', + 'Expression' )] - [Alias("RuleType")] - $ConditionalType="ContainsText" + [Alias('RuleType')] + $ConditionalType='ContainsText' ) $obj = [PSCustomObject]@{ diff --git a/__tests__/Compare-WorkSheet.tests.ps1 b/__tests__/Compare-WorkSheet.tests.ps1 index e119576..c4154b2 100644 --- a/__tests__/Compare-WorkSheet.tests.ps1 +++ b/__tests__/Compare-WorkSheet.tests.ps1 @@ -59,7 +59,16 @@ Describe "Compare Worksheet" { Context "Setting the background to highlight different rows" { BeforeAll { - $null = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) + if ($PSVersionTable.PSVersion.Major -ne 5) { + $null = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) + } + else { + $cmdline = 'Import-Module {0}; $null = Compare-WorkSheet "{1}" "{2}" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView; Start-Sleep -sec 5; exit' + $cmdline = $cmdline -f (Resolve-Path "$PSScriptRoot\..\importExcel.psd1" ) , + (Join-Path (Get-PSDrive TestDrive).root "server1.xlsx"), + (Join-Path (Get-PSDrive TestDrive).root "server2.xlsx") + powershell.exe -Command $cmdline + } $xl1 = Open-ExcelPackage -Path "TestDrive:\server1.xlsx" $xl2 = Open-ExcelPackage -Path "TestDrive:\server2.xlsx" $s1Sheet = $xl1.Workbook.Worksheets[1] diff --git a/__tests__/ConvertFrom-ExcelSheet.Tests.ps1 b/__tests__/ConvertFrom-ExcelSheet.Tests.ps1 new file mode 100644 index 0000000..f3021bc --- /dev/null +++ b/__tests__/ConvertFrom-ExcelSheet.Tests.ps1 @@ -0,0 +1,33 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')] +$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent +$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.xlsx" +$Outpath = "TestDrive:\" + +Describe 'ConvertFrom-ExcelSheet / Export-ExcelSheet' { + BeforeAll { + ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath + $firstText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv") + ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsText GridPosition,date + $SecondText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv") + ConvertFrom-ExcelSheet -Path $dataPath -OutputPath $Outpath -AsText "GridPosition" -Property driver, + @{n="date"; e={[datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#")}} , FinishPosition, GridPosition + $ThirdText = Get-Content (Join-path -Path $Outpath -ChildPath "First10Races.csv") + } + Context "Exporting to CSV" { + it "Exported the expected columns to a CSV file " { + $firstText[0] | should be '"Race","Date","FinishPosition","Driver","GridPosition","Team","Points"' + $SecondText[0] | should be '"Race","Date","FinishPosition","Driver","GridPosition","Team","Points"' + $ThirdText[0] | should be '"Driver","date","FinishPosition","GridPosition"' + } + it "Applied ASText and Properties correctly " { + $firstText[1] | should match '^"\w+","\d{5}","\d{1,2}","\w+ \w+","[1-9]\d?","\w+","\d{1,2}"$' + $secondText[1] | should match '^"\w+","\d\d \w{3,} \d{4}","\d","\w+ \w+","0\d","\w+","\d{1,2}"$' + $ThirdText[1] | should match '^"\w+ \w+","#\d\d/\d\d/\d{4}#","\d","0\d"$' + } + } + Context "Export aliased to ConvertFrom" { + it "Applied ASText and Properties correctly " { + (Get-Alias Export-ExcelSheet).source | should be "ImportExcel" + } + } +} \ No newline at end of file diff --git a/__tests__/First10Races.xlsx b/__tests__/First10Races.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5fe17090bf6468f103c58bdf843a84a7dbceaa99 GI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2=1Fw<7*1 zBa$0eKyWZC!h!P(J0b;EX)s%lhm!BWb3h-FrVHN(&Xqs4bTL!w(6&MP`r;MxL~Z-PBGK-rc6&_f+nBt>;wh%G%k+ z5DBuxJgWc~F4PI+H@zQR9Sv>(Z&<8Yj7+~5klqdxbY`6H3ReAUPJXCuCZo;y&kwffv4^!ANmc&T;2;Rj_O9B@fMMjgO@Dbxlmu1=8&;d`^guAV|~xw zVs|V@#7@D^%_1F6YLVVt5_CcKX`-+cUq|Pa)T&UM$~)e@wFj@q>E_1NZ6O!`A!)_I zv6E6EkPrSsE*Ll?sOJ3dkFEXFQ~&(@FAuRP$^N^7e}ACnpMtNS#h`HbtE~84O#CVM z=R*d6i~fNApGMq&K63D<@V~cu|1Amt1cOrl|G)A3Pd$J3|NgD10pWip@gLp5e`@)2 zxA1Q*qoDKzn$4ekhkq*gbG`F#1@fR$4W!`j)z3dg|NJTOwTntr})2f h^uLNfu>FhpKNwp{77Bzx000s6M-75;J?HDu{{trN{zm`+ literal 0 HcmV?d00001 diff --git a/__tests__/ImportExcelTests/Simple.tests.ps1 b/__tests__/ImportExcelTests/Simple.tests.ps1 index 47b6f1f..abb229c 100644 --- a/__tests__/ImportExcelTests/Simple.tests.ps1 +++ b/__tests__/ImportExcelTests/Simple.tests.ps1 @@ -1,8 +1,8 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')] Param() -if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) { - Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -} + +Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force + Describe "Tests" { BeforeAll { $data = $null diff --git a/mdHelp/en/ConvertFrom-ExcelSheet.md b/mdHelp/en/ConvertFrom-ExcelSheet.md new file mode 100644 index 0000000..ed25289 --- /dev/null +++ b/mdHelp/en/ConvertFrom-ExcelSheet.md @@ -0,0 +1,217 @@ +--- +external help file: ImportExcel-help.xml +Module Name: ImportExcel +online version: https://github.com/dfinke/ImportExcel +schema: 2.0.0 +--- + +# ConvertFrom-ExcelSheet + +## SYNOPSIS +Exports Sheets from Excel Workbooks to CSV files. + +## SYNTAX + +``` +ConvertFrom-ExcelSheet [-Path] [[-OutputPath] ] [[-SheetName] ] [[-Encoding] ] + [[-Extension] ] [[-Delimiter] ] [[-Property] ] [[-ExcludeProperty] ] [-Append] + [[-AsText] ] [] +``` + +## DESCRIPTION +This command provides a convenient way to run Import-Excel @ImportParameters | Select-Object @selectParameters | export-Csv @ ExportParameters +It can take the parameters -AsText , as used in Import-Excel, )Properties & -ExcludeProperties as used in Select-Object and +-Append, -Delimiter and -Encoding as used in Export-CSV + + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText GridPosition,date +``` + +First10Races.xlsx contains information about Motor races. The race date and grid (starting) position are stored with custom formats. +The command specifies the path to the file, and the directory to create the output file, and specifies that the columns "GridPosition" and "Date" should be treated as text to preserve their formatting + +### Example 2 +```powershell +PS C:\> ConvertFrom-ExcelSheet Path .\__tests__\First10Races.xlsx -OutputPath .. -AsText "GridPosition" -Property driver, @{n="date"; e={[datetime]::FromOADate($_.Date).tostring("#MM/dd/yyyy#")}} , FinishPosition, GridPosition +``` + +This uses the same file as example 1. Because the race date has a custom format, it imports as a number, +The requirement is to create a CSV file with the Driver, a specially formatted Date, FinishPostion and GridPostion (keeping its custom formatting). +The command specifies the path to the file, and the directory to create the output file, specifies that the column "GridPosition" should be treated as text instead of a number, and the output properties should be Driver, a calculated "date" field, FinishPosition and GridPsition. FromOADate converts the dates used by Excel (Days since Jan 1 1900) to a datetime object. + + +## PARAMETERS + +### -Append +Use this parameter to have the export add output to the end of the file. Without this parameter, the command replaces the file contents without warning. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsText +AsText allows selected columns to be returned as the text displayed in their cells, instead of their value. (* is supported as a wildcard.) + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 8 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Delimiter +Selects , or ; as the delimeter for the exported data - if not specified , is used by default. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: ;, , + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Encoding +Sets the text encoding for the output data file; UTF8 bu default + + +```yaml +Type: Encoding +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExcludeProperty + Specifies the properties that to exclude from the export. Wildcards are permitted. This parameter is effective only when the command also includes the Property parameter. + + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Extension +Sets the file extension for the exported data, defaults to CSV + + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: .txt, .log, .csv + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -OutputPath +The directory where the output file(s) will be created. The file name(s) will match the name of the workbook page which contained the data. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +The path to the .XLSX file which will be exported. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Property +Specifies the properties to select. Wildcards are permitted - the default is "*". +The value of the Property parameter can be a new calculated property, and follows the same pattern as Select-Item + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -SheetName +The name of a sheet to export, or a regular expression which is used to identify sheets + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object +## NOTES + +## RELATED LINKS