Dear Support,
Please see the attached “test.xlsx” sheet. I have a temp sheet through which I am creating pivots. I am able to create pivot except that the date values are not shown in the sorted order. Could you please suggest as what should I do to get the pivot s sorted by date i.e. with respect to this sheet “4/5/2013” is shown in end and not in the second column. Any suggestion would be much appreciated. Here is the code to create pivots:
private static void CreatePivotTablesSheet(Workbook workbook)
{
Style style = workbook.CreateStyle();
Worksheet sheet = workbook.Worksheets["temp"];
Cells cells = sheet.Cells;
Range cellRange = cells.MaxDisplayRange;
string sourcedata = cellRange.RefersTo.ToString();
//Obtaining the reference of the newly added worksheet
Worksheet pivotSheet = workbook.Worksheets[0];
pivotSheet.Name = "pivots";
PivotTableCollection pivotTables = pivotSheet.PivotTables;
//****************************************************************** jobPivotTable
int index = pivotTables.Add(sourcedata, 2, 0, "Job1Pivot");
//Accessing the instance of the newly added PivotTable
PivotTable jobPivotTable = pivotTables[index];
jobPivotTable.SaveData = true;
//Draging the "CUSTOMER" field to the row area.
jobPivotTable.AddFieldToArea(PivotFieldType.Row, 2);
//Draging the "DAY" field to the column area.
jobPivotTable.AddFieldToArea(PivotFieldType.Column, 0);
//Draging the "Mins" field to the data area.
jobPivotTable.AddFieldToArea(PivotFieldType.Data, 3);
//Accessing the data fields.
jobPivotTable.DataFields[0].DisplayName = "Job";
jobPivotTable.ColumnHeaderCaption = "DAY";
jobPivotTable.RowHeaderCaption = "Employee";
jobPivotTable.IsAutoFormat = true;
jobPivotTable.PivotTableStyleType = PivotTableStyleType.PivotTableStyleLight16;
//jobPivotTable.DataFields[0].NumberFormat = "#,##0.0";
jobPivotTable.DataFields[0].NumberFormat = "_(#,##0.0_);_((#,##0.0);_(\" - \"??_);_(@_)";
jobPivotTable.RowFields[0].IsAutoSort = true;
jobPivotTable.ColumnFields[0].IsAutoSort = true;
jobPivotTable.AutoFormatType = PivotTableAutoFormatType.Classic;
jobPivotTable.IsGridDropZones = true;
//******************************************************************
pivotSheet.AutoFitColumns();
workbook.AcceptAllRevisions();
}
I have also tried setting the style for first column
Style st = workbook.CreateStyle();
st.Number = 14;
string lastCell = "A" + (sheet.Cells.MaxDataRow + 1);
Range rng = sheet.Cells.CreateRange("A1:" + lastCell);
StyleFlag flag = new StyleFlag();
flag.All = true;
rng.ApplyStyle(st, flag);
It is not creating the pivots in the order the rows are shown in temp sheet. Please help.
Thank you,
Radha
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}<![endif]–>