Good morning, I am working with openXML creating a pivot table. I fill the XML with information, and create a table with the information just entered. the code that generates the pivot table is as follows
var pt = res.PivotTables.Add("PivotTable", res.Cell(1, 1), table.AsRange()); //res es una hoja de excel llamada "Resumen", tabla es la hoja donde saco la información para la tabla dinámica
//se agregan los registros que se van a agregar
pt.RowLabels.Add("Sucursal");
pt.RowLabels.Add("C. proveedor");
pt.RowLabels.Add("Proveedor");
pt.Values.Add("Total");
res.Column("D").Style.NumberFormat.Format = "$###,###,###.00";
return workbook.Deliver("Reporte por proveedores.xlsx");
The code works and generates the pivot table, but it does not give me the desired format, my system generates the report as follows:
campo1 campo2 campo3
datoColumna1
datoColumna2
datoColumna3
the idea is that the pivot table generates the data in the same column, something like this:
campo1 campo2 campo3
datoColumna1 datoColumna2 datoColumna3
I tried with these parameters but they don't affect the rows themselves:
pt.AutofitColumns = true;
pt.PreserveCellFormatting = true;
pt.SetAutofitColumns(true);
Apparently you have to apply the classic style to the pivot table so that it prints everything in the same row. To do this, you have to put the following line:
where "pt" is the variable we used to generate the pivot table.