Added Number Formatting

This commit is contained in:
dfinke
2016-03-26 13:57:21 -04:00
parent 41bca369c5
commit 5b0a528711
10 changed files with 73 additions and 4 deletions

View File

@@ -0,0 +1,13 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100
New-PSItem 1 -1
New-PSItem 1.2 -1.1
New-PSItem -3.2 -4.1
New-PSItem -5.2 6.1
)
$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat "[Blue]+0.#0;[Red]-0.#0"

View File

@@ -0,0 +1,15 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100
New-PSItem 1 -1
New-PSItem 1.2 -1.1
New-PSItem -3.2 -4.1
New-PSItem -5.2 6.1
New-PSItem 1000 -2000
)
$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat '[Blue]$#,##0.00;[Red]-$#,##0.00'

View File

@@ -0,0 +1,14 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
$data = $(
New-PSItem 1
New-PSItem .5
New-PSItem .3
New-PSItem .41
New-PSItem .2
New-PSItem -.12
)
$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat "0.0%;[Red]-0.0%"

View File

@@ -0,0 +1,11 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
$data = $(
New-PSItem 100 -100
New-PSItem 1 -1
New-PSItem 1.2 -1.1
)
$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat "0.#0;-0.#0"

View File

@@ -0,0 +1,7 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
Select DeviceID,Volumename,Size,Freespace |
Export-Excel -Path $file -Show -AutoSize -NumberFormat "0"

View File

@@ -0,0 +1,7 @@
$file = "disks.xlsx"
rm $file -ErrorAction Ignore
Get-CimInstance win32_logicaldisk -filter "drivetype=3" |
Select DeviceID,Volumename,Size,Freespace |
Export-Excel -Path $file -Show -AutoSize

View File

@@ -55,7 +55,8 @@ function Export-Excel {
[Switch]$AutoNameRange,
$StartRow=1,
$StartColumn=1,
[Switch]$PassThru
[Switch]$PassThru,
[string]$Numberformat="General"
)
Begin {
@@ -126,6 +127,7 @@ function Export-Excel {
$cellValue=$TargetData
if([Double]::TryParse($cellValue,[System.Globalization.NumberStyles]::Any,[System.Globalization.NumberFormatInfo]::InvariantInfo, [ref]$r)) {
$targetCell.Value = $r
$targetCell.Style.Numberformat.Format=$Numberformat
} else {
$targetCell.Value = $cellValue
}
@@ -171,6 +173,7 @@ function Export-Excel {
$r=$null
if([Double]::TryParse($cellValue,[System.Globalization.NumberStyles]::Any,[System.Globalization.NumberFormatInfo]::InvariantInfo, [ref]$r)) {
$targetCell.Value = $r
$targetCell.Style.Numberformat.Format=$Numberformat
} else {
$targetCell.Value = $cellValue
}

View File

@@ -4,7 +4,7 @@
RootModule = 'ImportExcel.psm1'
# Version number of this module.
ModuleVersion = '2.2.0'
ModuleVersion = '2.2.1'
# ID used to uniquely identify this module
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'

View File

@@ -1,8 +1,7 @@
$p = @{
Name = "ImportExcel"
NuGetApiKey = $NuGetApiKey
ReleaseNote = "Add Header param to Import-Html. Scope variabales Export-Excel"
ReleaseNote = "Add NumberFormat parameter"
}
Publish-Module @p

BIN
images/Formatting.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB