Existing pivot tables lost when saving updated workbook

Posted by: karl.richardson on 21 July 2023, 9:48 am EST

    • Post Options:
    • Link

    Posted 21 July 2023, 9:48 am EST - Updated 21 July 2023, 9:58 am EST

    I have created a spreadsheet via excel with a pivot table on a second sheet based on data in the first sheet.

    Programatically I then open that workbook via workbook.Open. I then add values to a known range of cells on the first sheet and save via workbook.Save (I have tried with and without specifying the type as xlsx).

    If I then open this saved copy in excel, the pivot table is no longer a pivot table, its just a range of ordinary cells.

    I have tried just opening it and then immediately saving it and see the same behavior. I can see the pivot table is there by inspecting the second sheet in my code once it is opened, so the save process is removing/corrupting it.

    I need the pivot table to be preserved on the resultant workbook, what do I need to do to ensure this?

    Update: I immediately solved my issue. I selected to add the data to the Data Model when adding the pivot table. When this is selected, saving the workbook breaks the data connection. I didn’t need this option, so it seems fine without it.

  • Posted 24 July 2023, 8:04 am EST

    Hello Karl,

    Apologies for the inconvenience casued.

    Can you please share the Excel file with which you are getting this issue and also let us know how you are population the data in it?

    A stripped-down sample would be very helpful.

    Regards,

    Prabhat Sharma.

  • Posted 24 July 2023, 11:00 am EST

    Many thanks for your reply. As noted in my update in the original post above, as is usually the way, I resolved my issue as soon as I posted to ask for help! When creating a pivot table in excel, it gives you the option to add it to the data model. This option was causing the breakage. I didn’t require that option anyway, so I simple disabled it.

    Many thanks again.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels