This commit is contained in:
dfinke
2015-09-11 11:11:40 -04:00
parent ed14807cdd
commit abaabc6fa1
2 changed files with 13 additions and 15 deletions

View File

@@ -24,10 +24,8 @@ function Export-Excel {
[bool]$TitleBold, [bool]$TitleBold,
[int]$TitleSize=22, [int]$TitleSize=22,
[System.Drawing.Color]$TitleBackgroundColor, [System.Drawing.Color]$TitleBackgroundColor,
#[string]$TitleBackgroundColor,
[string[]]$PivotRows, [string[]]$PivotRows,
[string[]]$PivotColumns, [string[]]$PivotColumns,
#[string[]]$PivotData,
$PivotData, $PivotData,
[string]$Password, [string]$Password,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Pie", [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Pie",
@@ -54,7 +52,7 @@ function Export-Excel {
$ws = $pkg | Add-WorkSheet -WorkSheetname $WorkSheetname -NoClobber:$NoClobber $ws = $pkg | Add-WorkSheet -WorkSheetname $WorkSheetname -NoClobber:$NoClobber
foreach($format in $ConditionalFormat ) { foreach($format in $ConditionalFormat ) {
#$obj = [PSCustomObject]@{ #$obj = [PSCustomObject]@{
# Address = $Address # Address = $Address
# Formatter = $ConditionalFormat # Formatter = $ConditionalFormat

View File

@@ -5,7 +5,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
function Import-Excel { function Import-Excel {
param( param(
[Alias("FullName")] [Alias("FullName")]
[Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory)] [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory)]
$Path, $Path,
$Sheet=1, $Sheet=1,
@@ -16,8 +16,8 @@ function Import-Excel {
$Path = (Resolve-Path $Path).Path $Path = (Resolve-Path $Path).Path
write-debug "target excel file $Path" 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 $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
$workbook = $xl.Workbook $workbook = $xl.Workbook
@@ -39,14 +39,14 @@ function Import-Excel {
foreach ($Column in 0..($Columns-1)) { foreach ($Column in 0..($Columns-1)) {
if($Header[$Column].Length -gt 0) { if($Header[$Column].Length -gt 0) {
$Name = $Header[$Column] $Name = $Header[$Column]
$h.$Name = $worksheet.Cells[$Row,($Column+1)].Value $h.$Name = $worksheet.Cells[$Row,($Column+1)].Text
} }
} }
[PSCustomObject]$h [PSCustomObject]$h
} }
$stream.Close() $stream.Close()
$stream.Dispose() $stream.Dispose()
$xl.Dispose() $xl.Dispose()
$xl = $null $xl = $null
} }
@@ -134,7 +134,7 @@ function ConvertFrom-ExcelSheet {
[CmdletBinding()] [CmdletBinding()]
param param
( (
[Alias("FullName")] [Alias("FullName")]
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[String] [String]
$Path, $Path,
@@ -151,7 +151,7 @@ function ConvertFrom-ExcelSheet {
) )
$Path = (Resolve-Path $Path).Path $Path = (Resolve-Path $Path).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 $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
$workbook = $xl.Workbook $workbook = $xl.Workbook
@@ -170,9 +170,9 @@ function ConvertFrom-ExcelSheet {
Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding
} }
$stream.Close() $stream.Close()
$stream.Dispose() $stream.Dispose()
$xl.Dispose() $xl.Dispose()
} }