diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 2df98bb..b4ef10b 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -1,17 +1,18 @@ function Export-Excel { <# - .Synopsis - .Example - gsv | Export-Excel .\test.xlsx - .Example - ps | Export-Excel .\test.xlsx -show\ - .Example - ps | Export-Excel .\test.xlsx -WorkSheetname Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM - .Example - ps | Export-Excel .\test.xlsx -WorkSheetname Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PM - .Example - Remove-Item "c:\temp\test.xlsx" -ErrorAction Ignore - Get-Service | Export-Excel "c:\temp\test.xlsx" -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} + .SYNOPSIS + Export data to an Excel work sheet. + .EXAMPLE + gsv | Export-Excel .\test.xlsx + .EXAMPLE + ps | Export-Excel .\test.xlsx -show\ + .EXAMPLE + ps | Export-Excel .\test.xlsx -WorkSheetname Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM + .EXAMPLE + ps | Export-Excel .\test.xlsx -WorkSheetname Processes -ChartType PieExploded3D -IncludePivotChart -IncludePivotTable -Show -PivotRows Company -PivotData PM + .EXAMPLE + Remove-Item "c:\temp\test.xlsx" -ErrorAction Ignore + Get-Service | Export-Excel "c:\temp\test.xlsx" -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} #> param( #[Parameter(Mandatory=$true)] diff --git a/Get-ExcelSheetInfo.ps1 b/Get-ExcelSheetInfo.ps1 index e60e9e5..6ab93f5 100644 --- a/Get-ExcelSheetInfo.ps1 +++ b/Get-ExcelSheetInfo.ps1 @@ -23,22 +23,28 @@ Function Get-ExcelSheetInfo { [CmdletBinding()] param( - [Alias("FullName")] + [Alias('FullName')] [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] $Path ) process { $Path = (Resolve-Path $Path).ProviderPath - write-debug "target excel file $Path" - $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite" + + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream $workbook = $xl.Workbook - if($workbook -and $workbook.Worksheets) { + + if ($workbook -and $workbook.Worksheets) { $workbook.Worksheets | Select-Object -Property name,index,hidden,@{ - Label = "Path" + Label = 'Path' Expression = {$Path} } } + + $stream.Close() + $stream.Dispose() + $xl.Dispose() + $xl = $null } } \ No newline at end of file diff --git a/Get-ExcelWorkbookInfo.ps1 b/Get-ExcelWorkbookInfo.ps1 new file mode 100644 index 0000000..acd2e92 --- /dev/null +++ b/Get-ExcelWorkbookInfo.ps1 @@ -0,0 +1,68 @@ +Function Get-ExcelWorkbookInfo { + <# + .SYNOPSIS + Retrieve information of an Excel workbook. + + .DESCRIPTION + The Get-ExcelWorkbookInfo cmdlet retrieves information (LastModifiedBy, LastPrinted, Created, Modified, ...) fron an Excel workbook. These are the same details that are visible in Windows Explorer when right clicking the Excel file, selecting Properties and check the Details tabpage. + + .PARAMETER Path + Specifies the path to the Excel file. This parameter is required. + + .EXAMPLE + Get-ExcelWorkbookInfo .\Test.xlsx + + CorePropertiesXml : #document + Title : + Subject : + Author : Konica Minolta User + Comments : + Keywords : + LastModifiedBy : Bond, James (London) GBR + LastPrinted : 2017-01-21T12:36:11Z + Created : 17/01/2017 13:51:32 + Category : + Status : + ExtendedPropertiesXml : #document + Application : Microsoft Excel + HyperlinkBase : + AppVersion : 14.0300 + Company : Secret Service + Manager : + Modified : 10/02/2017 12:45:37 + CustomPropertiesXml : #document + + .NOTES + CHANGELOG + 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + + .LINK + https://github.com/dfinke/ImportExcel + #> + + [CmdletBinding()] + Param ( + [Alias('FullName')] + [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] + [String]$Path + ) + + Process { + Try { + $Path = (Resolve-Path $Path).ProviderPath + + $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream + $workbook = $xl.Workbook + $workbook.Properties + + $stream.Close() + $stream.Dispose() + $xl.Dispose() + $xl = $null + } + Catch { + throw "Failed retrieving Excel workbook information for '$Path': $_" + } + } +} diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 756362f..1f0dce9 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -13,6 +13,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" . $PSScriptRoot\New-PSItem.ps1 . $PSScriptRoot\Pivot.ps1 . $PSScriptRoot\Get-ExcelSheetInfo.ps1 +. $PSScriptRoot\Get-ExcelWorkbookInfo.ps1 . $PSScriptRoot\Get-HtmlTable.ps1 . $PSScriptRoot\Import-Html.ps1 . $PSScriptRoot\Get-Range.ps1