Code Monkey home page Code Monkey logo

Comments (2)

RamblingCookieMonster avatar RamblingCookieMonster commented on August 23, 2024

Verified this outside of the Add-PivotTable functions. You can start with a fresh XLSX from EPPlus if desired, I used Export-XLSX to create it for simplicity sake.

Import-Module PSExcel

# Get the data ready
    $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
    }

# Path to export
    $Path = 'C:\temp\broken.xlsx'

# Start with a fresh xlsx, data only:
    $DemoData | Export-XLSX -Path $Path

# Open it in excel.  Everything works, everything looks good.  Worksheet1 is what we want.
    Invoke-Item $Path

# Add a pivot table...
    $Excel = New-Object OfficeOpenXml.ExcelPackage $Path
    $SourceWorkSheet = $Excel.Workbook.Worksheets['Worksheet1']
    $RangeCoordinates = $SourceWorkSheet.Dimension.Address

    $PivotWorkSheet = $Excel.Workbook.Worksheets.Add('PivotTable1')
    $PivotTable = $PivotWorkSheet.PivotTables.Add($PivotWorkSheet.Cells["A1"], $SourceWorkSheet.Cells[$RangeCoordinates], 'PivotTable1')
    $Excel.Save()
    $Excel.Dispose()

# Open it in excel.  Everything works, everything looks good.
# Worksheet1 and PivotTable1 are there.
    Invoke-Item $Path

# Add another pivot table...
    $Excel = New-Object OfficeOpenXml.ExcelPackage $Path
    $SourceWorkSheet = $Excel.Workbook.Worksheets['Worksheet1']
    $RangeCoordinates = $SourceWorkSheet.Dimension.Address

    $PivotWorkSheet = $Excel.Workbook.Worksheets.Add('PivotTable2')
    $PivotTable = $PivotWorkSheet.PivotTables.Add($PivotWorkSheet.Cells["A1"], $SourceWorkSheet.Cells[$RangeCoordinates], 'PivotTable2')
    $Excel.Save()
    $Excel.Dispose()

# No errors... but now open it in excel...
    Invoke-Item $Path

# Previously described issue occurs.

from psexcel.

RamblingCookieMonster avatar RamblingCookieMonster commented on August 23, 2024

This was indeed a bug in EPPlus, thanks to the contributors on that project for the fix!

from psexcel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.