Expanding Details in Pivot Table

Hi

I am trying to expand the details in a worksheet and cannot seem to figure out why it is not saving with expanded details. Please see attachments and notice in expected on page 4-5 you will see expanded info under studentId (what I am trying to get), but actual (page 4) does not have it.
Attached is worksheet, code, expected pdf and actual pdf.

Thanks,
Charlespivottable.zip (62.1 KB)

@ccuster68,
You may call WorkSheet.RefreshPivotTables() for each sheet before saving it as PDF. Please give a try to the following sample code and share your feedback.

var workbook = new Workbook(@"PivotTableCollapsed2016.xlsx");
var outputPath = @"actual.pdf";
foreach (var worksheet in workbook.Worksheets)
{
    foreach (var pt in worksheet.PivotTables)
    {
        for (int i = 0; i < pt.Fields(PivotFieldType.Column).Count; i++)
        {
            pt.Fields(PivotFieldType.Column)[i].HideDetail(false);
        }
        for (int i = 0; i < pt.Fields(PivotFieldType.Row).Count; i++)
        {
            pt.Fields(PivotFieldType.Row)[i].HideDetail(false);
        }
        pt.RefreshData();
    }
    worksheet.RefreshPivotTables();
}
workbook.Save(outputPath);

Perfect. Thanks again

@ccuster68,
Good to know that your issue is sorted out by the suggested line of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.