• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple Excel PowerShell module

Build status

PSExcel

IMPORTANT: This project is no longer maintained. Please consider Doug's excellent ImportExcel example, which is frequently updated by Doug and the community.

This is a rudimentary PowerShell module for working with Excel via the EPPlus library, with no dependencies on Excel itself.

  • Thanks to Doug Finke for his ImportExcel example - hadn't seen EPPlus before this!
  • Thanks to Philip Thompson for his expansive module illustrating how to work with EPPlus in PowerShell
  • Thanks to the team and contributors behind EPPlus for a fantastic solution allowing .NET Excel interaction, without Excel.

Caveats:

  • This covers limited functionality; contributions to this function or additional functions would be welcome!
  • Minimal testing. Contributions welcome!
  • Naming conventions subject to change. Suggestions welcome!

Functionality

  • Export random PowerShell output to Excel spreadsheets
  • Import Excel spreadsheets to PowerShell as objects
  • No dependency on Excel being installed

Instructions

# One time setup
    # Download the repository
    # Unblock the zip
    # Extract the PSExcel folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)

    #Simple alternative, if you have PowerShell 5, or the PowerShellGet module:
        Install-Module PSExcel

# Import the module.
    Import-Module PSExcel    #Alternatively, Import-Module \\Path\To\PSExcel

# Get commands in the module
    Get-Command -Module PSExcel

# Get help for a command
    Get-Help Import-XLSX -Full

# Export data to an XLSX spreadsheet
    Get-ChildItem C:\ -File |
        Export-XLSX -Path C:\Files.xlsx

# Import data from an XLSX spreadsheet
    Import-XLSX -Path C:\Files.xlsx

Examples

Several examples are available on the accompanying blog post and the embedded Gist.

Some highlights:

Export and import data

#Create some demo data
    $DemoData = 1..10 | Foreach-Object{

        $EID = Get-Random -Minimum 1 -Maximum 1000
        $Date = (Get-Date).adddays(-$EID)

        New-Object -TypeName PSObject -Property @{
            Name = "jsmith$_"
            EmployeeID = $EID
            Date = $Date
        } | Select Name, EmployeeID, Date
    }

# Export it
    $DemoData | Export-XLSX -Path C:\temp\Demo.xlsx

# Import it back
    $Imported = Import-XLSX -Path C:\Temp\Demo.xlsx -Header samaccountname, EID, Date

Verify that it exported:

Excel

Check the data we imported back:

Imported data

Fun with formatting

Freeze panes:

# Open the previously created Excel file...
    $Excel = New-Excel -Path C:\temp\Demo.xlsx

# Get a Worksheet
    $Worksheet = $Excel | Get-Worksheet -Name Worksheet1

# Freeze the top row
    $Worksheet | Set-FreezePane -Row 2

# Save and close!
    $Excel | Close-Excel -Save

Freeze panes

Format the header:

# Re-open the file
    $Excel = New-Excel -Path C:\temp\Demo.xlsx

# Add bold, size 15 formatting to the header
    $Excel |
        Get-WorkSheet |
        Format-Cell -Header -Bold $True -Size 14

# Save and re-open the saved changes
    $Excel = $Excel | Save-Excel -Passthru

Header format

Format the first column:

#  Text was too large!  Set it to 11
    $Excel |
        Get-WorkSheet |
        Format-Cell -Header -Size 11

    $Excel |
        Get-WorkSheet |
        Format-Cell -StartColumn 1 -EndColumn 1 -Autofit -AutofitMinWidth -AutofitMaxWidth 7 -Color DarkRed

# Save and close
    $Excel | Save-Excel -Close

First column

Create tables

Why format the columns yourself? Create a table (thanks to awiddersheim!):

# Add a table, autofit the data.  We use force to overwrite our previous demo.
    $DemoData | Export-XLSX -Path C:\Temp\Demo.xlsx -Table -Autofit -Force

Table

Pivot tables and charts

This is straight from Doug Finke's fantastic ImportExcel module:

# Fun with pivot tables and charts! Props to Doug Finke
    Get-ChildItem $env:USERPROFILE -Recurse -File |
        Export-XLSX -Path C:\Temp\Files.xlsx -PivotRows Extension -PivotValues Length -ChartType Pie

Pivot

Notes

Note that while some of these examples leverage PowerShell version 3 or later language, the module itself should work with PowerShell 2, and all Pester tests run against both PowerShell 2 and PowerShell 4.

More Repositories

1

PowerShell

Various PowerShell functions and scripts
PowerShell
953
star
2

Invoke-Parallel

Speed up PowerShell with simplified multithreading
PowerShell
384
star
3

PSDeploy

Simple PowerShell based deployments
PowerShell
347
star
4

PSSQLite

PowerShell module to query SQLite databases
PowerShell
309
star
5

PSDepend

PowerShell Dependency Handler
PowerShell
282
star
6

PSSlack

PowerShell module for simple Slack integration
PowerShell
274
star
7

BuildHelpers

Helper functions for PowerShell CI/CD scenarios
PowerShell
215
star
8

SecretServer

Secret Server PowerShell Module
PowerShell
87
star
9

PSStackExchange

PowerShell module to query Stack Exchange API
PowerShell
81
star
10

PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
PowerShell
47
star
11

PSHTMLTable

PowerShell module to spice up ad hoc notifications and reports
PowerShell
38
star
12

Git-Presentation

Presentation materials for Git and GitHub TechSession
34
star
13

WritingModules

Material accompanying PowerShell + DevOps Summit session
PowerShell
32
star
14

PSDiskPart

DiskPart PowerShell Module
PowerShell
32
star
15

Infoblox

Infoblox PowerShell Module
PowerShell
30
star
16

PSNeo4j

Simple Neo4j PowerShell Wrapper
PowerShell
29
star
17

ADGrouper

Define dynamic AD security group membership via yaml
PowerShell
19
star
18

Dots

A janky, neo4j based CMDB glued together with PowerShell
PowerShell
16
star
19

Citrix.NetScaler

PowerShell module for working with Citrix NetScaler REST API
PowerShell
15
star
20

PSRT

PowerShell wrapper for Request Tracker
PowerShell
10
star
21

TireFire

A janky PowerShell module to simplify managing notes and their metadata
PowerShell
7
star
22

PSStash

Atlassian Stash PowerShell Module
PowerShell
7
star
23

PSPagerDuty

Simple PowerShell PagerDuty module
PowerShell
7
star
24

PSLDAPQueryLogging

PowerShell module to simplify configuring AD LDAP diagnostic logging
PowerShell
7
star
25

PSPuppetDB

Simple module for querying the PuppetDB API
PowerShell
6
star
26

CommunityLightningDemos2017

Proposals, and eventually demo material for Community Lightning Demos
PowerShell
6
star
27

Wait-Path

Wait for a path to exist
PowerShell
5
star
28

PSSensu

Simple PowerShell module for working with the Sensu Go API
PowerShell
3
star
29

RamblingCookieMonster.github.io

CSS
3
star
30

SessionMaterials

Materials or links to materials from sessions I've participated in
PowerShell
3
star
31

lisa-kitchen-demo

Example used for Test-Kitchen demo
PowerShell
2
star
32

AppVeyor-DSC-Test

POC to test DSC configurations on a fresh VM from AppVeyor
PowerShell
2
star
33

AppVReporting

App-V Reporting PowerShell Module
PowerShell
2
star
34

zAppVeyor-Explore

PowerShell
1
star
35

wip

Stuff that doesn't have a home yet
PowerShell
1
star