Comments (2)
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.
This was indeed a bug in EPPlus, thanks to the contributors on that project for the fix!
from psexcel.
Related Issues (20)
- Cannot find type [OfficeOpenXml.ExcelPackage]: verify that the assembly containing this type is loaded. HOT 2
- Join-Worksheet ignores specified parameter "DestinationWorksheetName" HOT 1
- Detecting Macros HOT 3
- ReadOnly HOT 1
- Export-XLSX -WorkSheetName "More Then 31 characters" HOT 1
- AutoFit errors out when run run within an Inline function HOT 1
- Merge cells
- Possibility to specify date format
- Operation is not supported. (Exception from HRESULT: 0x80131515) HOT 3
- Error saving file (on Ubuntu) HOT 1
- [Feature Request] Feature loading references and running excel VBA macros HOT 1
- Case sensitivity bug on linux
- Please use the latest EPPlus lib,now it is 4.5.2.1 HOT 1
- How to create multiple worksheet in one workbook?
- NameError: global name 'component_names' is not defined
- duplicated rows invalidates file
- Powershell core
- Add LiteralPath parameter HOT 1
- Add readonly feature HOT 1
- Cannot update column data in Excel file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from psexcel.