Hi Charlie,
Here is my testing code using your file (I eliminated the pivot table in the second sheet. Attached is the source file and output file.):
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//workbook.Open(@"Pivot_No1.xls");//source workbook
workbook.Open(Server.MapPath(@"\CellsApp\Designer\Pivot_No1.xls"));
workbook.Worksheets.Add();
Worksheet sheet2 = workbook.Worksheets[1];
sheet2.Name = "Summary";
PivotTables pTables = sheet2.PivotTables;
string sourceData = "=Data!A1:L29";
string destCellName = "A3";
int index = pTables.Add(sourceData, destCellName, "PivotTable2");
// access the new pivottable
PivotTable pTable = pTables[index];
// drag 1st field to the row data
pTable.AddFieldToArea(PivotFieldType.Row, 1); // product
// drag 1st field to the row data
pTable.AddFieldToArea(PivotFieldType.Column, 6); // fcastdate
// drag 1st field to the row data
pTable.AddFieldToArea(PivotFieldType.Data, 4); // quantity
//Accessing the row fields.
PivotFields rowPivotFields = pTable.RowFields;
//Accessing the first row field in the row fields.
PivotField rowPivotField = rowPivotFields[0];
//Setting Subtotals.
rowPivotField.SetSubtotals(PivotFieldSubtotalType.Sum, true);
rowPivotField.SetSubtotals(PivotFieldSubtotalType.Count, true);
//Setting autosort options.
//Setting the field auto sort.
rowPivotField.IsAutoSort = true;
//Setting the field auto sort ascend.
rowPivotField.IsAscendSort = true;
//Accessing the column fields.
PivotFields colPivotFields = pTable.ColumnFields;
//Accessing the first col field in the col fields.
PivotField colPivotField = colPivotFields[0];
//Setting Subtotals.
colPivotField.SetSubtotals(PivotFieldSubtotalType.Sum, true);
colPivotField.SetSubtotals(PivotFieldSubtotalType.Count, true);
//Setting autosort options.
//Setting the field auto sort.
colPivotField.IsAutoSort = true;
//Setting the field auto sort ascend.
colPivotField.IsAscendSort = true;
MemoryStream stream = new MemoryStream();
workbook.Save(stream, FileFormatType.Default);
Response.ContentType = "application/vnd.ms-excel";
//This is same as OpenInBrowser option
//Response.AddHeader("content-disposition", "inline; filename=PTable1_new.xls");
Response.BinaryWrite(stream.ToArray());
Thank you.