Hello,
Aren´t pivot tables still not fully supported? I got some pivot table working but the behaviour is more than strange. After hours of investigation my pivot table with aprox. 15k of rows is crashing when workbook is opened (message: Feature removed....).
Pivot table is feeded from dataset and what´s strange the crash does not appear evertime workbook is opened, e.g. when I limit dataset to TOP 20 rows everything works fine, sometimes even 15 rows are not working. I´m getting really crazy because of this.
Can you give me some guide what should I be focused on? ...empty cells, data types in my database?
The code:
Aren´t pivot tables still not fully supported? I got some pivot table working but the behaviour is more than strange. After hours of investigation my pivot table with aprox. 15k of rows is crashing when workbook is opened (message: Feature removed....).
Pivot table is feeded from dataset and what´s strange the crash does not appear evertime workbook is opened, e.g. when I limit dataset to TOP 20 rows everything works fine, sometimes even 15 rows are not working. I´m getting really crazy because of this.
Can you give me some guide what should I be focused on? ...empty cells, data types in my database?
The code:
'Excel file definition
Dim wb As XLWorkbook = New XLWorkbook()
'Get data from dataset
Dim con = New SqlConnection(ConfigurationManager.ConnectionStrings("IPSdb").ConnectionString)
con.Open()
Dim cmd As New SqlCommand
Dim cmdstring As String = "SELECT Partnumber, Qty, Week, Year, Line, CBID FROM tblEDI"
cmd.CommandType = CommandType.Text
Dim objAdp = New SqlDataAdapter(cmdstring, con)
Dim ds = New DataSet()
objAdp.Fill(ds, "tblEDI")
Dim sheet1 = wb.Worksheets.Add("EDI raw data")
sheet1.Cell(1, 1).InsertTable(ds.Tables("tblEDI"), False, False)
Dim dataRange = sheet1.RangeUsed
'Add a new sheet for our pivot table
Dim sheet2 = wb.Worksheets.Add("PivotTable")
'Create the pivot table, using the data from the table
Dim pt = sheet2.PivotTables.AddNew("PivotTable", sheet2.Cell(1, 1), dataRange)
pt.RowLabels.Add("Partnumber")
pt.RowLabels.Add("Line")
pt.RowLabels.Add("CBID")
pt.ColumnLabels.Add("Year")
pt.ColumnLabels.Add("Week")
pt.Values.Add("Qty")
'Pivot format
With pt
.SortFieldsAtoZ = True
.ShowGrandTotalsColumns = False
.ShowGrandTotalsRows = False
.Theme = XLPivotTableTheme.PivotStyleLight1
.Subtotals = XLPivotSubtotals.DoNotShow
.Layout = XLPivotLayout.Tabular
.PreserveCellFormatting = True
.AutofitColumns = True
End With
'Adjust workbook and save
For Each ws As IXLWorksheet In wb.Worksheets
ws.ShowGridLines = False
ws.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left
ws.Columns.AdjustToContents()
Next
'Save Excel file to ExportedFiles
wb.SaveAs(path & "EDIexport " & Day(Today()) & "." & Month(Today()) & "." & Year(Today()) & ".xlsx")
fileexists = True