Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:59:32+00:00 2026-06-03T00:59:32+00:00

I have a excel sheet with one chart which is the source. My target

  • 0

I have a excel sheet with one chart which is the source. My target is a powerpoint presentation with 3 slides. I need to update slide #3 with the Chart in the excel file.

After executing the application and when I try to open the pptx file I get a “Powerpoint found a problem with content”. After I repair I notice that I always get a blank slide in Slide #2 which shows I am not updating the correct slide.

What should I do to go to the slide based on slide no. (I don’t have chart titles in the powerpoint slide and the excel chart) and why am I getting a invalid content error.

I Would greatly appreciate your help. Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using OpenXmlPkg = DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

namespace ExportChart
{
class Program
{
    static void Main(string[] args)
    {
        string SourceFile = "Projected Sales.xlsx";
        string TargetFile = "Projected Sales.pptx";
        string targetppt = "Generatedppt.pptx";

        ChartPart chartPart;
        ChartPart newChartPart;
        SlidePart slidepartbkMark = null;
        string chartPartIdBookMark = null;

        File.Copy(TargetFile, targetppt, true);

        //Powerpoint document 
        using (OpenXmlPkg.PresentationDocument pptPackage = OpenXmlPkg.PresentationDocument.Open(targetppt, true))
        {

            OpenXmlPkg.PresentationPart presentationPart = pptPackage.PresentationPart;

            var secondSlidePart = pptPackage.PresentationPart.SlideParts.Skip(1).Take(1);
            foreach (var slidepart in pptPackage.PresentationPart.SlideParts)
            {

            slidepartbkMark = slidepart;

                if (slidepart.GetPartsCountOfType<ChartPart>() != 0)
                {
                    chartPart = slidepart.ChartParts.First();
                    chartPartIdBookMark = slidepart.GetIdOfPart(chartPart);
                    slidepart.DeletePart(chartPart);
                    slidepart.Slide.Save();
                }

                //return;
            }

            newChartPart = slidepartbkMark.AddNewPart<ChartPart>(chartPartIdBookMark);

            ChartPart saveXlsChart = null;
            using (SpreadsheetDocument xlsDocument = SpreadsheetDocument.Open(SourceFile.ToString(), true))
            {
                WorkbookPart xlsbookpart = xlsDocument.WorkbookPart;

                foreach (var worksheetPart in xlsDocument.WorkbookPart.WorksheetParts)
                {
                    if (worksheetPart.DrawingsPart != null)
                        if (worksheetPart.DrawingsPart.ChartParts.Any())
                        {
                            saveXlsChart = worksheetPart.DrawingsPart.ChartParts.First();
                        }
                }


                newChartPart.FeedData(saveXlsChart.GetStream());
                slidepartbkMark.Slide.Save();
                xlsDocument.Close();
                pptPackage.Close();
            }
        }
    }
}     

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:59:35+00:00Added an answer on June 3, 2026 at 12:59 am

    If there is anybody who is looking how to identify a slide with a slide number you need to do the following

    //Get the relationship id 
    SlideIdList s = documentPart.Presentation.SlideIdList;
    SlideId nslideid = (SlideId)s.ElementAt(slideno-1); //slide no is the number of the slide
    string slidRelId = nslideid.RelationshipId;
    

    Next iterate through each slide using a loop. Within the foreach loop add the following code to see if a slide has a particular relationship id

    //  get the relationshipid of the current slide 
        string thisSlideno = documentPart.GetIdOfPart(slidePart);
        if (thisSlideno == slidRelId)
        {
            //do your actions
        }
    

    I hope this is helpful

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel spreadsheet which is one sheet with a table and chart
I have one excel file (*.xlsm) with VBA code on first sheet: Private Sub
I have published my Excel workbook (which is one sheet with pivot-data linked to
I have an Excel sheet with two column, one is a number , and
I'm having trouble with some Excel data validation. On one sheet, I have a
I have a Excel sheet with two columns and I need to create new
I am preparing an Excel sheet in which I have to maintain the version
I have a PowerPoint template that contains one slide and on that slide is
I have an excel sheet where one column consist of comma seprated hyperlinks. However,
I have an Excel workbook with a number of features: One main user-facing sheet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.