Get-Workbook.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Get-Workbook {
    <#
    .SYNOPSIS
        Return a Workbook from an ExcelPackage
 
    .DESCRIPTION
        Return a Workbook from an ExcelPackage
 
    .PARAMETER Excel
        ExcelPackage to extract workbook from
     
    .EXAMPLE
        $Excel = New-Excel -Path "C:\Excel.xlsx"
        $WorkBook = Get-Workbook $Excel
        $WorkBook
 
        #Open C:\Excel.xlsx, view the workbook
 
    .NOTES
        Thanks to Doug Finke for his example:
            https://github.com/dfinke/ImportExcel/blob/master/ImportExcel.psm1
 
        Thanks to Philip Thompson for an expansive set of examples on working with EPPlus in PowerShell:
            https://excelpslib.codeplex.com/
 
    .LINK
        https://github.com/RamblingCookieMonster/PSExcel
 
    .FUNCTIONALITY
        Excel
    #>

    [OutputType([OfficeOpenXml.ExcelWorkbook])]
    [cmdletbinding()]
    param(
        [parameter( Mandatory=$true,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$false)]
        [OfficeOpenXml.ExcelPackage]$Excel
    )
    Process
    {
        $Excel.WorkBook
    }
}