mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +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
|
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 {
|
Process {
|
||||||
|
if($firstTimeThru) {
|
||||||
if(!$Header) {
|
$firstTimeThru=$false
|
||||||
|
$isDataTypeValueType = $TargetData.GetType().name -match "string|bool|byte|char|decimal|double|float|int|long|sbyte|short|uint|ulong|ushort"
|
||||||
$ColumnIndex = 1
|
|
||||||
$Header = $TargetData.psobject.properties.name
|
|
||||||
|
|
||||||
foreach ($Name in $Header) {
|
|
||||||
$ws.Cells[$Row, $ColumnIndex].Value = $name
|
|
||||||
$ColumnIndex += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$Row += 1
|
if($isDataTypeValueType) {
|
||||||
$ColumnIndex = 1
|
$ColumnIndex = 1
|
||||||
|
|
||||||
foreach ($Name in $Header) {
|
|
||||||
|
|
||||||
$targetCell = $ws.Cells[$Row, $ColumnIndex]
|
$targetCell = $ws.Cells[$Row, $ColumnIndex]
|
||||||
|
|
||||||
$cellValue=$TargetData.$Name
|
|
||||||
|
|
||||||
$r=$null
|
$r=$null
|
||||||
|
$cellValue=$TargetData
|
||||||
if([double]::tryparse($cellValue, [ref]$r)) {
|
if([double]::tryparse($cellValue, [ref]$r)) {
|
||||||
$targetCell.Value = $r
|
$targetCell.Value = $r
|
||||||
} else {
|
} else {
|
||||||
@@ -122,6 +116,42 @@ function Export-Excel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ColumnIndex += 1
|
$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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
RootModule = 'ImportExcel.psm1'
|
RootModule = 'ImportExcel.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '1.8'
|
ModuleVersion = '1.81'
|
||||||
|
|
||||||
# ID used to uniquely identify this module
|
# ID used to uniquely identify this module
|
||||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ $p = @{
|
|||||||
NuGetApiKey = $NuGetApiKey
|
NuGetApiKey = $NuGetApiKey
|
||||||
LicenseUri = "https://github.com/dfinke/ImportExcel/blob/master/LICENSE.txt"
|
LicenseUri = "https://github.com/dfinke/ImportExcel/blob/master/LICENSE.txt"
|
||||||
Tag = "Excel","EPPlus","Export","Import"
|
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"
|
ProjectUri = "https://github.com/dfinke/ImportExcel"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -24,6 +24,14 @@ Know Issues
|
|||||||
|
|
||||||
What's new
|
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
|
#### 9/25/2015
|
||||||
|
|
||||||
@@ -35,7 +43,7 @@ Got a great request from [forensicsguy20012004](https://github.com/forensicsguy2
|
|||||||
##### Example
|
##### Example
|
||||||
Here, you create four worksheets named `PM`,`Handles`,`Services` and `Files`.
|
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
|
$p = Get-Process
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user