I'm using EPPlus to create Excel reports.
Now i'm trying to create a Pivot with a DateTime
PageField
, so that the user can filter the period he want to see by himself. But although i can filter this for year,month or days in the according data worksheet by default, i don't get it working in the Pivot.
Here is what i have:
Dim wsPivot = excel.Workbook.Worksheets.Add("Pivot")
Dim wsData = excel.Workbook.Worksheets.Add("Data")
Dim source = workSheet.GetDataSource
wsData.Cells("A1").LoadFromDataTable(source, True, OfficeOpenXml.Table.TableStyles.Medium6)
For Each col As DataColumn In source.Columns
If col.DataType = GetType(Date) Then
Dim colNumber = col.Ordinal + 1
Dim range = wsData.Cells(1, colNumber, source.Rows.Count, colNumber)
range.Style.Numberformat.Format = "dd.mm.yyyy"
End If
Next
Dim dataRange = wsData.Cells(wsData.Dimension.Address.ToString())
dataRange.AutoFitColumns()
Dim pivotTable = wsPivot.PivotTables.Add(wsPivot.Cells("A3"), dataRange, "Open Contacts")
pivotTable.PageFields.Add(pivotTable.Fields("OwnedAt")) '** this is the date column i want to group **'
pivotTable.PageFields.Add(pivotTable.Fields("Owner"))
pivotTable.RowFields.Add(pivotTable.Fields("Country"))
pivotTable.ColumnFields.Add(pivotTable.Fields("Status"))
pivotTable.DataFields.Add(pivotTable.Fields("Count"))
It's only possible to select datetime values from the list including hours and minutes and not to group by month f.e.(see picture below).
Here is the filter-list from the data-worksheet. How to get this in pivot?
Thank you in advance.
Note: I've also asked this on codeplex without success. Maybe someone else can help even if he has no experiences with EPPlus but knows similar issues with other libraries. I could split the DateTime values into separate columns per sql(year,month,day). But i'm afraid that the pivot will get more confusing with so many fields( i also would have to split the other date fields). Even with no experiences at all in programatically generating pivots, what would experienced excel users(i'm not) recommend?