RamblingCookieMonster / PSExcel

A simple Excel PowerShell module

Home Page:http://ramblingcookiemonster.github.io/PSExcel-Intro/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When using empty arrays, Worksheets won't get added, resulting in a corrupt xlsx

moonwitch opened this issue · comments

Index operation failed; the array index evaluated to null.
At C:\Program Files\WindowsPowerShell\Modules\PSExcel\1.0.2\Export-XLSX.ps1:477 char:17

  • ... $WorkSheet.Cells[$WorkSheet.Dimension.Address].AutoFitCol ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArrayIndex

Long story short, I have to create a report where I have a list of AD groups, the report follows the format AD Groupname as Sheetname, the groupmembers go into the sheets. Some groups are empty, and on those groups - this errors out.

I would like to add: This is indeed caused by feeding $null into the width (-Autofit)
Not sure if this is a bug then, but if you use the switch and have empty values (PSObject), you will have a corrupt xlsx.

Hi!

Good find, and thanks for the follow up detail, should make it easier to track down!

Feel free to poke around if you'd like, would be happy to take a PR - otherwise, will try to take a peek (might be a few weeks).

Cheers!

Not published in the gallery, but put in a test to skip applying autofit if there's no data - guessing there might be other switches with similar behavior. Thanks for pointing out where and why this was failing!