Dyota's blog

Excel Export

I have some defaults that I like to apply when I use Export-Excel. These are things that I always do manually, but it's nice to spit out a whole bunch of data files where it's formatted nicely.

The thing to note is that Export-Excel doesn't have flags for every single thing that I want to do, but fortunately, it can pass along the object, and we can operate on that object using methods.

    $excel = $data |
        Export-Excel -Path $outfilename -TableName "Table1" -TableStyle 'Light9' -Title "$title" -AutoSize -PassThru

    # Hide gridlines on the first worksheet
    $excel.Workbook.Worksheets[1].View.ShowGridLines = $false

    # Freeze at row 3 (freezes rows 1-2), no column freeze
    $excel.Workbook.Worksheets[1].View.FreezePanes(3, 1)

    # Save and close
    Close-ExcelPackage $excel