mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 15:53:32 +00:00
Better handling of Empry values when setting Columns/Rows
This commit is contained in:
@@ -156,7 +156,8 @@
|
|||||||
if ($PSBoundParameters.ContainsKey('Value')) { foreach ($row in ($StartRow..$endRow)) {
|
if ($PSBoundParameters.ContainsKey('Value')) { foreach ($row in ($StartRow..$endRow)) {
|
||||||
if ($Value -is [scriptblock]) { #re-create the script block otherwise variables from this function are out of scope.
|
if ($Value -is [scriptblock]) { #re-create the script block otherwise variables from this function are out of scope.
|
||||||
$cellData = & ([scriptblock]::create( $Value ))
|
$cellData = & ([scriptblock]::create( $Value ))
|
||||||
Write-Verbose -Message $cellData
|
if ($null -eq $cellData) {Write-Verbose -Message "Script block evaluates to null."}
|
||||||
|
else {Write-Verbose -Message "Script block evaluates to '$cellData'"}
|
||||||
}
|
}
|
||||||
else { $cellData = $Value}
|
else { $cellData = $Value}
|
||||||
if ($cellData -match "^=") { $Worksheet.Cells[$Row, $Column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care
|
if ($cellData -match "^=") { $Worksheet.Cells[$Row, $Column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care
|
||||||
@@ -169,8 +170,8 @@
|
|||||||
$Worksheet.Cells[$Row, $Column].HyperLink = $h
|
$Worksheet.Cells[$Row, $Column].HyperLink = $h
|
||||||
}
|
}
|
||||||
else {$Worksheet.Cells[$Row, $Column].HyperLink = $cellData }
|
else {$Worksheet.Cells[$Row, $Column].HyperLink = $cellData }
|
||||||
$Worksheet.Cells[$Row, $Column].Style.Font.Color.SetColor([System.Drawing.Color]::Blue)
|
|
||||||
$Worksheet.Cells[$Row, $Column].Style.Font.UnderLine = $true
|
$Worksheet.Cells[$Row, $Column].Style.Font.UnderLine = $true
|
||||||
|
$Worksheet.Cells[$Row, $Column].Style.Font.Color.SetColor([System.Drawing.Color]::Blue)
|
||||||
}
|
}
|
||||||
else { $Worksheet.Cells[$Row, $Column].Value = $cellData }
|
else { $Worksheet.Cells[$Row, $Column].Value = $cellData }
|
||||||
if ($cellData -is [datetime]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = 'm/d/yy h:mm' } # This is not a custom format, but a preset recognized as date and localized.
|
if ($cellData -is [datetime]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = 'm/d/yy h:mm' } # This is not a custom format, but a preset recognized as date and localized.
|
||||||
|
|||||||
@@ -147,7 +147,8 @@
|
|||||||
if ($Value -is [scriptblock] ) {
|
if ($Value -is [scriptblock] ) {
|
||||||
#re-create the script block otherwise variables from this function are out of scope.
|
#re-create the script block otherwise variables from this function are out of scope.
|
||||||
$cellData = & ([scriptblock]::create( $Value ))
|
$cellData = & ([scriptblock]::create( $Value ))
|
||||||
Write-Verbose -Message $cellData
|
if ($null -eq $cellData) {Write-Verbose -Message "Script block evaluates to null."}
|
||||||
|
else {Write-Verbose -Message "Script block evaluates to '$cellData'"}
|
||||||
}
|
}
|
||||||
else{$cellData = $Value}
|
else{$cellData = $Value}
|
||||||
if ($cellData -match "^=") { $Worksheet.Cells[$Row, $column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care
|
if ($cellData -match "^=") { $Worksheet.Cells[$Row, $column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care
|
||||||
|
|||||||
Reference in New Issue
Block a user