Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Commented Issue: support for pivot table and pivot chart [10158]

$
0
0
Hello,
I need support for pivot table and pivot chart. I need support for changing ranges of pivot table and refresh pivot charts and pivot tables.
I need it in xlsx files, but if also xls files are supported it will be better.
Comments: ** Comment from web user: roneil_txhyd **

XLSX files created with a pivot table through the XSSFSheet, XSSFPivotTable, etc. classes will not open correctly in Excel 2013 and 2016.

The following error is displayed:
"Excel found unreadable content in '[filename]'. Do you wish to recover the contents of this work book? ... "

Clicking Yes displays the following:
"Excel was able to open the file by repairing or removing the unreadable content.
Removed Part: /xl/pivotCache/pivotCacheDefinition1.xml part with XML error. (PivotTable cache) Catastrophic failure Line 1, column 0.
Removed Part: /xl/pivotTables/pivotTable1.xml part with XML error. (PivotTable view) Catastrophic failure Line 1, column 0."

And the workbook contains no pivot table.

Source code (VB.NET from example in POI documentation):
```
Private Sub PoiPivotExample()
Dim wb As New XSSFWorkbook()
Dim sheet As XSSFSheet = wb.CreateSheet()

' Create some data to build the pivot table on
SetCellData(sheet)

Dim pivotTable As XSSFPivotTable = sheet.CreatePivotTable(New AreaReference("A1:D4"), New CellReference("H5"))

' Configure the pivot table
' Use first column as row label
pivotTable.AddRowLabel(0)

' Sum up the second column
pivotTable.AddColumnLabel(DataConsolidateFunction.SUM, 1)

' Set the third column as filter
pivotTable.AddColumnLabel(DataConsolidateFunction.AVERAGE, 2)

' Add filter on forth column
pivotTable.AddReportFilter(3)

Dim filePath As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "ooxml-pivottable.xlsx")

Using fileOut As FileStream = File.Create(filePath)
wb.Write(fileOut)
fileOut.Close()
wb.Close()
End Using
End Sub

Private Sub SetCellData(sheet As XSSFSheet)
Dim row1 As XSSFRow = sheet.CreateRow(0)
' Create a cell and put a value in it.
Dim cell11 As XSSFCell = row1.CreateCell(0)
cell11.setCellValue("Names")
Dim cell12 As XSSFCell = row1.CreateCell(1)
cell12.setCellValue("#")
Dim cell13 As XSSFCell = row1.CreateCell(2)
cell13.setCellValue("%")
Dim cell14 As XSSFCell = row1.CreateCell(3)
cell14.setCellValue("Human")

Dim row2 As XSSFRow = sheet.CreateRow(1)
Dim cell21 As XSSFCell = row2.CreateCell(0)
cell21.setCellValue("Jane")
Dim cell22 As XSSFCell = row2.CreateCell(1)
cell22.setCellValue(10)
Dim cell23 As XSSFCell = row2.CreateCell(2)
cell23.setCellValue(100)
Dim cell24 As XSSFCell = row2.CreateCell(3)
cell24.setCellValue("Yes")

Dim row3 As XSSFRow = sheet.CreateRow(2)
Dim cell31 As XSSFCell = row3.CreateCell(0)
cell31.setCellValue("Tarzan")
Dim cell32 As XSSFCell = row3.CreateCell(1)
cell32.setCellValue(5)
Dim cell33 As XSSFCell = row3.CreateCell(2)
cell33.setCellValue(90)
Dim cell34 As XSSFCell = row3.CreateCell(3)
cell34.setCellValue("Yes")

Dim row4 As XSSFRow = sheet.CreateRow(3)
Dim cell41 As XSSFCell = row4.CreateCell(0)
cell41.setCellValue("Terk")
Dim cell42 As XSSFCell = row4.CreateCell(1)
cell42.setCellValue(10)
Dim cell43 As XSSFCell = row4.CreateCell(2)
cell43.setCellValue(90)
Dim cell44 As XSSFCell = row4.CreateCell(3)
cell44.setCellValue("No")
End Sub
```

An example output file is attached.


Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>