This PowerShell Module wraps the .NET EPPlus DLL (included). Easily integrate reading and writing Excel spreadsheets into PowerShell, without launching Excel in the background. You can also automate the creation of Pivot Tables and Charts.
There are two ways to install this module. If you are running PowerShell V5
Install-Module -Name ImportExcel
Otherwise To install in your personal modules folder (e.g. ~\Documents\WindowsPowerShell\Modules), run:
iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/ImportExcel/master/Install.ps1')
- Using
-IncludePivotTable
, if that pivot table name exists, you'll get an error.- Investigating a solution
- Workaround delete the Excel file first, then do the export
- Added Styles for Tables.
Examples Get-Process|Export-Excel foo.xlsx -TableName "Processes" -TableStyle "Medium17" -Show
- Added a tag to set the color of a Cell. you can set the Foreground color or the Background AND the foreground.
- Just add the tag in the Cell value
Examples Set Foregroung [red]::This is my text
Set Background and Foreground [red,white]::This is my text
$usa_states=@{ "CA" = "California";
"NY" = "[red,white]::New York";
"IL" = "[red]::Illinois";
"NH" = "New Hampshire"}
$test = @()
foreach ($item in $usa_states.keys) {
$ObjFastping = New-Object pscustomobject
Add-Member -InputObject $ObjFastping -MemberType NoteProperty -Name state -Value $item
Add-Member -InputObject $ObjFastping -MemberType NoteProperty -Name name -Value $usa_states[$item]
$test+=$ObjFastping
}
$test | Export-Excel -Path c:\temp\test.xlsx
- For -PivotRows you can pass a
hashtable
with the name of the property and the type of calculation.Sum
,Average
,Max
,Min
,Product
,StdDev
,StdDevp
,Var
,Varp
Get-Service |
Export-Excel "c:\temp\test.xlsx" `
-Show `
-IncludePivotTable `
-PivotRows status `
-PivotData @{status='count'}
6/16/2015 (Thanks Justin)
- Improvements to PivotTable overwriting
- Added two parameters to Export-Excel
- RangeName - Turns the data piped to Export-Excel into a named range.
- TableName - Turns the data piped to Export-Excel into an excel table.
Examples
Get-Process|Export-Excel foo.xlsx -Verbose -IncludePivotTable -TableName "Processes" -Show
Get-Process|Export-Excel foo.xlsx -Verbose -IncludePivotTable -RangeName "Processes" -Show
- Fixed null header problem
- Added three parameters:
- FreezeTopRow - Freezes the first row of the data
- AutoFilter - Enables filtering for the data in the sheet
- BoldTopRow - Bolds the top row of data, the column headers
Example
Get-CimInstance win32_service |
select state, accept*, start*, caption |
Export-Excel test.xlsx -Show -BoldTopRow -AutoFilter -FreezeTopRow -AutoSize
- Published to PowerShell Gallery. In PowerShell v5 use
Find-Module importexcel
thenFind-Module importexcel | Install-Module
- datetime properties were displaying as ints, now are formatted
- Now you can create multiple Pivot tables in one pass
- Thanks to pscookiemonster, he submitted a repro case to the EPPlus CodePlex project and got it fixed
$ps = ps
$ps |
Export-Excel .\testExport.xlsx -WorkSheetname memory `
-IncludePivotTable -PivotRows Company -PivotData PM `
-IncludePivotChart -ChartType PieExploded3D
$ps |
Export-Excel .\testExport.xlsx -WorkSheetname handles `
-IncludePivotTable -PivotRows Company -PivotData Handles `
-IncludePivotChart -ChartType PieExploded3D -Show
- Included and embellished Claus Nielsen function to take all sheets in an Excel file workbook and create a text file for each
ConvertFrom-ExcelSheet
- Renamed
Export-MultipleExcelSheets
toConvertFrom-ExcelSheet
- You can add a title to the Excel "Report"
Title
,TitleFillPattern
,TitleBold
,TitleSize
,TitleBackgroundColor
- Thanks to Irwin Strachan for this and other great suggestions, testing and more
- Renamed
AutoFitColumns
toAutoSize
- Implemented
Export-MultipleExcelSheets
- Implemented
-Password
for a worksheet - Replaced
-Force
switch with-NoClobber
switch - Added examples for
Get-Help
- If Pivot table is requested, that sheet becomes the tab selected
- Implemented exporting data to named sheets via the -WorkSheename parameter.
gsv | Export-Excel .\test.xlsx -WorkSheetname Services
dir -file | Export-Excel .\test.xlsx -WorkSheetname Files
ps | Export-Excel .\test.xlsx -WorkSheetname Processes -IncludePivotTable -Show -PivotRows Company -PivotData PM
Reads each sheet in TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt
ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data
Reads and outputs sheets like Sheet10 and Sheet20 form TestSheets.xlsx and outputs it to the data directory as the sheet name with the extension .txt
ConvertFrom-ExcelSheet .\TestSheets.xlsx .\data sheet?0
You can set the pattern, size and of if the title is bold.
$p=@{
Title = "Process Report as of $(Get-Date)"
TitleFillPattern = "LightTrellis"
TitleSize = 18
TitleBold = $true
Path = "$pwd\testExport.xlsx"
Show = $true
AutoSize = $true
}
Get-Process |
Where Company | Select Company, PM |
Export-Excel @p
$p = Get-Process
$DataToGather = @{
PM = {$p|select company, pm}
Handles = {$p|select company, handles}
Services = {gsv}
Files = {dir -File}
Albums = {(Invoke-RestMethod http://www.dougfinke.com/powershellfordevelopers/albums.js)}
}
Export-MultipleExcelSheets -Show -AutoSize .\testExport.xlsx $DataToGather
NOTE If the sheet exists when using -WorkSheetname parameter, it will be deleted and then added with the new data.
Click on this image to watch the short video.
You can also find EPPLus on Nuget.