mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Handle data that is _not_ an object #41
This commit is contained in:
@@ -86,31 +86,25 @@ function Export-Excel {
|
||||
throw $Error[0].Exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
$firstTimeThru = $true
|
||||
$isDataTypeValueType=$false
|
||||
$pattern = "string|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort"
|
||||
}
|
||||
|
||||
Process {
|
||||
|
||||
if(!$Header) {
|
||||
|
||||
$ColumnIndex = 1
|
||||
$Header = $TargetData.psobject.properties.name
|
||||
|
||||
foreach ($Name in $Header) {
|
||||
$ws.Cells[$Row, $ColumnIndex].Value = $name
|
||||
$ColumnIndex += 1
|
||||
}
|
||||
if($firstTimeThru) {
|
||||
$firstTimeThru=$false
|
||||
$isDataTypeValueType = $TargetData.GetType().name -match "string|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort"
|
||||
}
|
||||
|
||||
$Row += 1
|
||||
$ColumnIndex = 1
|
||||
|
||||
foreach ($Name in $Header) {
|
||||
|
||||
if($isDataTypeValueType) {
|
||||
$ColumnIndex = 1
|
||||
|
||||
$targetCell = $ws.Cells[$Row, $ColumnIndex]
|
||||
|
||||
$cellValue=$TargetData.$Name
|
||||
|
||||
$r=$null
|
||||
$cellValue=$TargetData
|
||||
if([double]::tryparse($cellValue, [ref]$r)) {
|
||||
$targetCell.Value = $r
|
||||
} else {
|
||||
@@ -122,7 +116,43 @@ function Export-Excel {
|
||||
}
|
||||
|
||||
$ColumnIndex += 1
|
||||
}
|
||||
$Row += 1
|
||||
|
||||
} else {
|
||||
if(!$Header) {
|
||||
|
||||
$ColumnIndex = 1
|
||||
$Header = $TargetData.psobject.properties.name
|
||||
|
||||
foreach ($Name in $Header) {
|
||||
$ws.Cells[$Row, $ColumnIndex].Value = $name
|
||||
$ColumnIndex += 1
|
||||
}
|
||||
}
|
||||
|
||||
$Row += 1
|
||||
$ColumnIndex = 1
|
||||
|
||||
foreach ($Name in $Header) {
|
||||
|
||||
$targetCell = $ws.Cells[$Row, $ColumnIndex]
|
||||
|
||||
$cellValue=$TargetData.$Name
|
||||
|
||||
$r=$null
|
||||
if([double]::tryparse($cellValue, [ref]$r)) {
|
||||
$targetCell.Value = $r
|
||||
} else {
|
||||
$targetCell.Value = $cellValue
|
||||
}
|
||||
|
||||
switch ($TargetData.$Name) {
|
||||
{$_ -is [datetime]} {$targetCell.Style.Numberformat.Format = "m/d/yy h:mm"}
|
||||
}
|
||||
|
||||
$ColumnIndex += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
End {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
RootModule = 'ImportExcel.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.8'
|
||||
ModuleVersion = '1.81'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||
|
||||
@@ -4,7 +4,7 @@ $p = @{
|
||||
NuGetApiKey = $NuGetApiKey
|
||||
LicenseUri = "https://github.com/dfinke/ImportExcel/blob/master/LICENSE.txt"
|
||||
Tag = "Excel","EPPlus","Export","Import"
|
||||
ReleaseNote = "Now you can hide worksheets using the -HideSheet paramater"
|
||||
ReleaseNote = "Can now handle data that is _not_ an object"
|
||||
ProjectUri = "https://github.com/dfinke/ImportExcel"
|
||||
}
|
||||
|
||||
|
||||
10
README.md
10
README.md
@@ -24,6 +24,14 @@ Know Issues
|
||||
|
||||
What's new
|
||||
-
|
||||
#### 9/30/2015
|
||||
|
||||
Export-Excel can now handle data that is **not** an object
|
||||
|
||||
echo a b c 1 $true 2.1 1/1/2015 | Export-Excel c:\temp\test.xlsx -Show
|
||||
Or
|
||||
|
||||
dir -Name | Export-Excel c:\temp\test.xlsx -Show
|
||||
|
||||
#### 9/25/2015
|
||||
|
||||
@@ -35,7 +43,7 @@ Got a great request from [forensicsguy20012004](https://github.com/forensicsguy2
|
||||
##### Example
|
||||
Here, you create four worksheets named `PM`,`Handles`,`Services` and `Files`.
|
||||
|
||||
The last line creates the `Files` sheet and then hides the `Handles`,`Services`
|
||||
The last line creates the `Files` sheet and then hides the `Handles`,`Services` sheets.
|
||||
|
||||
$p = Get-Process
|
||||
|
||||
|
||||
Reference in New Issue
Block a user