mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Added Number Formatting
This commit is contained in:
13
Examples/NumberFormat/ColorizeNumbers.ps1
Normal file
13
Examples/NumberFormat/ColorizeNumbers.ps1
Normal 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"
|
||||
15
Examples/NumberFormat/CurrencyFormat.ps1
Normal file
15
Examples/NumberFormat/CurrencyFormat.ps1
Normal 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'
|
||||
|
||||
14
Examples/NumberFormat/PercentagFormat.ps1
Normal file
14
Examples/NumberFormat/PercentagFormat.ps1
Normal 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%"
|
||||
11
Examples/NumberFormat/PosNegNumbers.ps1
Normal file
11
Examples/NumberFormat/PosNegNumbers.ps1
Normal 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"
|
||||
7
Examples/NumberFormat/Win32LogicalDisk.ps1
Normal file
7
Examples/NumberFormat/Win32LogicalDisk.ps1
Normal 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"
|
||||
7
Examples/NumberFormat/Win32LogicalDiskFormatted.ps1
Normal file
7
Examples/NumberFormat/Win32LogicalDiskFormatted.ps1
Normal 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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
BIN
images/Formatting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
Reference in New Issue
Block a user