This commit is contained in:
dfinke
2016-12-22 12:01:16 -05:00
parent 29e44e0aa1
commit 221bc5d215
3 changed files with 43 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ function Export-Excel {
Get-Service | Export-Excel "c:\temp\test.xlsx" -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'}
#>
param(
[Parameter(Mandatory=$true)]
#[Parameter(Mandatory=$true)]
$Path,
[Parameter(ValueFromPipeline=$true)]
$TargetData,
@@ -51,7 +51,6 @@ function Export-Excel {
[Object[]]$ConditionalFormat,
[Object[]]$ConditionalText,
[Object[]]$ExcelChartDefinition,
# [Object[]]$CellStyle,
[ScriptBlock]$CellStyleSB,
[string[]]$HideSheet,
[Switch]$KillExcel,
@@ -59,7 +58,8 @@ function Export-Excel {
$StartRow=1,
$StartColumn=1,
[Switch]$PassThru,
[string]$Numberformat="General"
[string]$Numberformat="General",
[Switch]$Now
)
Begin {
@@ -70,7 +70,15 @@ function Export-Excel {
}
try {
if($Now) {
$Path=[System.IO.Path]::GetTempFileName() -replace "\.tmp",".xlsx"
$Show=$true
$AutoSize=$true
$AutoFilter=$true
}
$Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
if (Test-Path $path) {
Write-Debug "File `"$Path`" already exists"
}

View File

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

View File

@@ -28,6 +28,37 @@ iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfi
# What's new
#### 12/22/2016
- Added `-Now` switch. This short cuts the process, automatically creating a temp file and enables the `-Show`, `-AutoFilter`, `-AutoSize` switches.
```powershell
Get-Process | Select Company, Handles | Export-Excel -Now
```
- Added ScriptBlocks for coloring cells. Check out
```powershell
Get-Process |
Select-Object Company,Handles,PM, NPM|
Export-Excel $xlfile -Show -AutoSize -CellStyleSB {
param(
$workSheet,
$totalRows,
$lastColumn
)
Set-CellStyle $workSheet 1 $LastColumn Solid Cyan
foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 0})) {
Set-CellStyle $workSheet $row $LastColumn Solid Gray
}
foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 1})) {
Set-CellStyle $workSheet $row $LastColumn Solid LightGray
}
}
```
#### 9/28/2016
[Fixed](https://github.com/dfinke/ImportExcel/pull/126) Powershell 3.0 compatibility. Thanks to [headsphere](https://github.com/headsphere). He used `$obj.PSObject.Methods[$target]` snytax to make it backward compatible. PS v4.0 and later allow `$obj.$target`.