none
Not able to load an image on second slide of PPT RRS feed

  • Question

  • Hi,

    I am trying to export two charts from application into a .PPT. In this when we tried to export second chart on second slide of PPT then header image not available to second slide.

    So can you please provide me the C# code or any help for this.

    Thanks,

    Ajeet Kumar Yadav

    • Moved by CoolDadTx Thursday, February 25, 2016 3:59 PM Office related
    Thursday, February 25, 2016 1:58 PM

Answers

  • Hi, Ajeet Kumar Yadav

    the following code will help you to add header logo in each slide.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Office.Interop.PowerPoint;
    using Microsoft.Office.Core;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                string pictureFileName = @"C:\Users\Administrator\Desktop\logo.png";
    
                Application pptApplication = new Application();
    
                Microsoft.Office.Interop.PowerPoint.Slides slides;
                Microsoft.Office.Interop.PowerPoint._Slide slide;
               // Microsoft.Office.Interop.PowerPoint.TextRange objText;
    
                // Create the Presentation File
                Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
    
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
    
                // Create new Slide
                slides = pptPresentation.Slides;
                slide = slides.AddSlide(1, customLayout);
    
                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Master.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left=5 , shape.Top=5, shape.Width= 100 , shape.Height=100);
                pptPresentation.SaveAs(@"C:\Users\Administrator\Desktop\fppt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
                //pptPresentation.Close();
                //pptApplication.Quit();
    
            }
        }
    }
    

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Friday, March 11, 2016 9:56 AM
    Moderator

All replies

  • Hi, Ajeet Kumar Yadav<o:p></o:p>

    You describe your issue in just 2 lines. You did not mention the details regarding your issue also did not provide some code to reproduce your issue. So it is quite difficult to understand your issue at this stage I need to confirm some details about your issue. <o:p></o:p>

    >>You mention that you trying to export 2 charts from application (from which application?) to .ppt. how you are performing this operation by manually or by some code?<o:p></o:p>

    >> you mention that when you try to export 2<sup>nd</sup> chart (so your 1<sup>st</sup> chart exported correctly or not?) the header image is not available. So is your chart loaded? Or just header image is disappeared from slide.<o:p></o:p>

    >> you want c# code. (regarding export chart or it is related with the header image)<o:p></o:p>

    >> if it is possible please provide a code if you performing this operation by code. If you are not performing this operation by code then provide the steps you are performing.<o:p></o:p>

    Regards<o:p></o:p>

    Deepak<o:p></o:p>

    Friday, February 26, 2016 9:52 AM
    Moderator
  • Hi Deepak,

    I am adding images in content area to a ppt using Presentation class (http://www.codeproject.com/script/Content/ViewAssociatedFile.aspx?rzp=%2FKB%2Foffice%2FCreatePPTUsingTemplate%2F%2Fcreatepptusingtemplate_src.zip&zep=PowerPointslids%2FPowerPointslids%2FPresentation.cs&obid=16328&obtid=2&ovid=1), but I want to add a header logo  (image) in my each slide.

    I have also tried to apply theme ( https://msdn.microsoft.com/en-us/library/office/cc850846.aspx ) but when theme applied successfully but the content of generated ppt not shown as default but when change theme in Powerpoint manually then content in ppt visible.

    So can you please provide me the C# code or any help for this.

    Thanks,

    Ajeet Kumar Yadav


    Friday, February 26, 2016 11:39 AM
  • Hi, Ajeet Kumar Yadav

    the following code will help you to add header logo in each slide.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Office.Interop.PowerPoint;
    using Microsoft.Office.Core;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                string pictureFileName = @"C:\Users\Administrator\Desktop\logo.png";
    
                Application pptApplication = new Application();
    
                Microsoft.Office.Interop.PowerPoint.Slides slides;
                Microsoft.Office.Interop.PowerPoint._Slide slide;
               // Microsoft.Office.Interop.PowerPoint.TextRange objText;
    
                // Create the Presentation File
                Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
    
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
    
                // Create new Slide
                slides = pptPresentation.Slides;
                slide = slides.AddSlide(1, customLayout);
    
                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Master.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left=5 , shape.Top=5, shape.Width= 100 , shape.Height=100);
                pptPresentation.SaveAs(@"C:\Users\Administrator\Desktop\fppt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
                //pptPresentation.Close();
                //pptApplication.Quit();
    
            }
        }
    }
    

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Friday, March 11, 2016 9:56 AM
    Moderator
  • That's very interesting stuff to know about. Thank you so much for the valuable information.
    Friday, August 2, 2019 5:21 AM
  • Whenever you need to place constant content on some or all presentation slides, you can use slide master. Here is an solution based on Free Spire.Presentation.

    //initialize a new Presentation and load the sample file
    Presentation presentation = new Presentation();
    presentation.LoadFromFile(@"sample.pptx");
    //get the first slide master
    IMasterSlide master = presentation.Masters[0];
    //append image to slide master
    String image = @"logo.png";
    RectangleF rff = new RectangleF(40, 40, 100, 80);
    IEmbedImage pic=master.Shapes.AppendEmbedImage(ShapeType.Rectangle, image, rff);
    pic.Line.FillFormat.FillType = FillFormatType.None;
    //add new slide to presentation
    presentation.Slides.Append();
    //save and launch the file
    presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
    System.Diagnostics.Process.Start("result.pptx");

    Monday, August 5, 2019 3:02 AM