mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
formatted
This commit is contained in:
@@ -194,10 +194,10 @@ Function Export-Excel {
|
||||
https://github.com/dfinke/ImportExcel
|
||||
#>
|
||||
|
||||
[CmdletBinding(DefaultParameterSetName='Default')]
|
||||
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
||||
Param(
|
||||
$Path,
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[Parameter(ValueFromPipeline = $true)]
|
||||
$TargetData,
|
||||
[String]$WorkSheetname = 'Sheet1',
|
||||
[String]$Title,
|
||||
@@ -223,12 +223,12 @@ Function Export-Excel {
|
||||
[Switch]$FreezeFirstColumn,
|
||||
[Switch]$FreezeTopRowFirstColumn,
|
||||
[Int[]]$FreezePane,
|
||||
[Parameter(ParameterSetName='Default')]
|
||||
[Parameter(ParameterSetName = 'Default')]
|
||||
[Switch]$AutoFilter,
|
||||
[Switch]$BoldTopRow,
|
||||
[Switch]$NoHeader,
|
||||
[String]$RangeName,
|
||||
[ValidateScript({
|
||||
[ValidateScript( {
|
||||
if ($_.Contains(' ')) {
|
||||
throw 'Tablename has spaces.'
|
||||
}
|
||||
@@ -242,9 +242,9 @@ Function Export-Excel {
|
||||
$true
|
||||
}
|
||||
})]
|
||||
[Parameter(ParameterSetName='Table')]
|
||||
[Parameter(ParameterSetName = 'Table')]
|
||||
[String]$TableName,
|
||||
[Parameter(ParameterSetName='Table')]
|
||||
[Parameter(ParameterSetName = 'Table')]
|
||||
[OfficeOpenXml.Table.TableStyles]$TableStyle = 'Medium6',
|
||||
[Object[]]$ExcelChartDefinition,
|
||||
[String[]]$HideSheet,
|
||||
@@ -362,7 +362,7 @@ Function Export-Excel {
|
||||
|
||||
$R = $null
|
||||
|
||||
if ([Double]::TryParse([String]$Value,[System.Globalization.NumberStyles]::Any,
|
||||
if ([Double]::TryParse([String]$Value, [System.Globalization.NumberStyles]::Any,
|
||||
[System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$R)) {
|
||||
$R
|
||||
}
|
||||
@@ -386,11 +386,10 @@ Function Export-Excel {
|
||||
}
|
||||
|
||||
if ($Now) {
|
||||
$Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp','.xlsx'
|
||||
$Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx'
|
||||
$Show = $true
|
||||
$AutoSize = $true
|
||||
if (!$TableName)
|
||||
{
|
||||
if (!$TableName) {
|
||||
$AutoFilter = $true
|
||||
}
|
||||
}
|
||||
@@ -491,11 +490,11 @@ Function Export-Excel {
|
||||
$totalRows = $ws.Dimension.Rows
|
||||
$totalColumns = $ws.Dimension.Columns
|
||||
|
||||
foreach($c in 0..($totalColumns-1)) {
|
||||
foreach ($c in 0..($totalColumns - 1)) {
|
||||
$targetRangeName = "$($script:Header[$c])"
|
||||
|
||||
$targetColumn = $c+1
|
||||
$theCell = $ws.Cells[2,$targetColumn,$totalRows,$targetColumn ]
|
||||
$targetColumn = $c + 1
|
||||
$theCell = $ws.Cells[2, $targetColumn, $totalRows, $targetColumn ]
|
||||
$ws.Names.Add($targetRangeName, $theCell) | Out-Null
|
||||
|
||||
if ([OfficeOpenXml.FormulaParsing.ExcelUtilities.ExcelAddressUtil]::IsValidAddress($targetRangeName)) {
|
||||
@@ -528,7 +527,7 @@ Function Export-Excel {
|
||||
$cer = $ws.Dimension.End.Row
|
||||
$cec = $script:Header.Count
|
||||
|
||||
$targetRange = $ws.Cells[$csr, $csc, $cer,$cec]
|
||||
$targetRange = $ws.Cells[$csr, $csc, $cer, $cec]
|
||||
$tbl = $ws.Tables.Add($targetRange, $TableName)
|
||||
$tbl.TableStyle = $TableStyle
|
||||
}
|
||||
@@ -539,7 +538,7 @@ Function Export-Excel {
|
||||
|
||||
$wsPivot.View.TabSelected = $true
|
||||
|
||||
$pivotTableDataName=$WorkSheetname + 'PivotTableData'
|
||||
$pivotTableDataName = $WorkSheetname + 'PivotTableData'
|
||||
|
||||
$pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells['A1'], $ws.Cells[$dataRange], $pivotTableDataName)
|
||||
|
||||
@@ -592,29 +591,29 @@ Function Export-Excel {
|
||||
}
|
||||
|
||||
if ($AutoFilter) {
|
||||
$ws.Cells[$dataRange].AutoFilter=$true
|
||||
$ws.Cells[$dataRange].AutoFilter = $true
|
||||
}
|
||||
|
||||
if ($FreezeTopRow) {
|
||||
$ws.View.FreezePanes(2,1)
|
||||
$ws.View.FreezePanes(2, 1)
|
||||
}
|
||||
|
||||
if ($FreezeTopRowFirstColumn) {
|
||||
$ws.View.FreezePanes(2,2)
|
||||
$ws.View.FreezePanes(2, 2)
|
||||
}
|
||||
|
||||
if ($FreezeFirstColumn) {
|
||||
$ws.View.FreezePanes(1,2)
|
||||
$ws.View.FreezePanes(1, 2)
|
||||
}
|
||||
|
||||
if ($FreezePane) {
|
||||
$freezeRow,$freezeColumn=$FreezePane
|
||||
$freezeRow, $freezeColumn = $FreezePane
|
||||
if (-not $freezeColumn -or $freezeColumn -eq 0) {
|
||||
$freezeColumn=1
|
||||
$freezeColumn = 1
|
||||
}
|
||||
|
||||
if ($freezeRow -gt 1) {
|
||||
$ws.View.FreezePanes($freezeRow,$freezeColumn)
|
||||
$ws.View.FreezePanes($freezeRow, $freezeColumn)
|
||||
}
|
||||
}
|
||||
if ($BoldTopRow) {
|
||||
@@ -635,9 +634,9 @@ Function Export-Excel {
|
||||
$pkg.Workbook.WorkSheets[$Sheet].Hidden = 'Hidden'
|
||||
}
|
||||
|
||||
$chartCount=0
|
||||
$chartCount = 0
|
||||
foreach ($chartDef in $ExcelChartDefinition) {
|
||||
$ChartName = 'Chart' + (Split-Path -Leaf ([System.IO.path]::GetTempFileName())) -replace 'tmp|\.',''
|
||||
$ChartName = 'Chart' + (Split-Path -Leaf ([System.IO.path]::GetTempFileName())) -replace 'tmp|\.', ''
|
||||
$chart = $ws.Drawings.AddChart($ChartName, $chartDef.ChartType)
|
||||
$chart.Title.Text = $chartDef.Title
|
||||
|
||||
@@ -650,22 +649,23 @@ Function Export-Excel {
|
||||
$chart.Datalabel.ShowPercent = $chartDef.ShowPercent
|
||||
}
|
||||
|
||||
$chart.SetPosition($chartDef.Row, $chartDef.RowOffsetPixels,$chartDef.Column, $chartDef.ColumnOffsetPixels)
|
||||
$chart.SetPosition($chartDef.Row, $chartDef.RowOffsetPixels, $chartDef.Column, $chartDef.ColumnOffsetPixels)
|
||||
$chart.SetSize($chartDef.Width, $chartDef.Height)
|
||||
|
||||
$chartDefCount = @($chartDef.YRange).Count
|
||||
if ($chartDefCount -eq 1) {
|
||||
$Series=$chart.Series.Add($chartDef.YRange, $chartDef.XRange)
|
||||
$Series = $chart.Series.Add($chartDef.YRange, $chartDef.XRange)
|
||||
|
||||
$SeriesHeader=$chartDef.SeriesHeader
|
||||
$SeriesHeader = $chartDef.SeriesHeader
|
||||
if (-not $SeriesHeader) {
|
||||
$SeriesHeader = 'Series 1'
|
||||
}
|
||||
|
||||
$Series.Header = $SeriesHeader
|
||||
} else {
|
||||
for($idx = 0; $idx -lt $chartDefCount; $idx += 1) {
|
||||
$Series=$chart.Series.Add($chartDef.YRange[$idx], $chartDef.XRange)
|
||||
}
|
||||
else {
|
||||
for ($idx = 0; $idx -lt $chartDefCount; $idx += 1) {
|
||||
$Series = $chart.Series.Add($chartDef.YRange[$idx], $chartDef.XRange)
|
||||
|
||||
if ($chartDef.SeriesHeader.Count -gt 0) {
|
||||
$SeriesHeader = $chartDef.SeriesHeader[$idx]
|
||||
@@ -685,12 +685,12 @@ Function Export-Excel {
|
||||
foreach ($targetConditionalText in $ConditionalText) {
|
||||
$target = "Add$($targetConditionalText.ConditionalType)"
|
||||
|
||||
$Range=$targetConditionalText.Range
|
||||
$Range = $targetConditionalText.Range
|
||||
if (-not $Range) {
|
||||
$Range = $ws.Dimension.Address
|
||||
}
|
||||
|
||||
$rule=($ws.Cells[$Range].ConditionalFormatting).PSObject.Methods[$target].Invoke()
|
||||
$rule = ($ws.Cells[$Range].ConditionalFormatting).PSObject.Methods[$target].Invoke()
|
||||
|
||||
if ($targetConditionalText.Text) {
|
||||
if ($targetConditionalText.ConditionalType -match 'equal|notequal|lessthan|lessthanorequal|greaterthan|greaterthanorequal') {
|
||||
|
||||
Reference in New Issue
Block a user