0

I am using VB Net and telerik controls to build a web application. I have a screen with a few ColumnChart RadHtmlCharts on, and I need to get them into a PowerPoint Presentation in the Code Behind file.

My current approach is taking an existing .PPTX file and stepping through it, replacing text where required and so on. Now I just need to get the charts into the presentation.

Here is the loop that I am making through the slides.

    ' generate
    For Each slide As SlidePart In pCopy.PresentationPart.SlideParts

        ' THIS IS WHERE THE CHARTS NEED TO BE ADDED TO THE SLIDE

    Next

Note: I have written a function that returns the chart, all I am missing now is the steps required to get it into the presentation.

Here are the 'Imports' I have included...

Imports Telerik.Web.UI 
Imports System.Data 
Imports System.IO 
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.PowerPoint 
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging 
Imports DocumentFormat.OpenXml.Presentation

Any help will be greatly appreciated

2 Answers2

1

Just as rdmptn has suggested I took the chart and saved that as an image first, and then from there added the images to the slides using templates.

So the basic steps I took were...

1) Create Powerpoint presentation with a holding image in (name the image via the 'Selection Pane')

2) In the Code Behind loop through all of the slideparts, checking if the name of the part (image) is the chart we are looking for

3) Using the following code replace the holding image with the generated image of the chart (GenerateChartImage() returns the filepath to the generated image)

                Using imgStream As FileStream = New FileStream(GenerateChartImage(), FileMode.Open)
                    imagePart.FeedData(imgStream)
                End Using

Here is how I saved the chart as an image (where generate chart just builds the chart programatically...

    Dim Chart As New RadChart()

    Dim FilePath As String = "~/Folder/" & FileName & ".jpg"
    Dim Path As String = Server.MapPath(FilePath)

    Chart = GenerateChart(Index)

    ' save the image and return the filepath
    Chart.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg)

    return Path

I hope this helps someone else as I understand this topic can be very confusing!

0

Assuming you know how to put images in the pptx file (I, myself, don't), you "only" need to get the images from the HtmlChart. There several approaches:

  1. start from the following code library on exporting the control: http://www.telerik.com/support/code-library/exporting-radhtmlchart-to-png-and-pdf Using the ClientExportManager control is quite straightforward.

  2. this should provide you with an image of the chart on your server that you can use in your existing code

Other ideas you can consider:

rdmptn
  • 5,413
  • 1
  • 16
  • 29
  • Yes this is the approach that I took. Initially I was using the new RadHtmlChart which is a much better looking chart, but has slightly limited options in terms of exporting in the way I needed. Therefore I switched to the older RadChart which gave me the option to save the chart as an image, but looks much older and isn't animated etc. – Russ Dooley Oct 07 '15 at 08:12
  • An image saved from RadHtmlChart will not be animated either. Also, RadChart is not supported by Telerik anymore. Just saying. I hope you manage to get the features you are looking for in your project. – rdmptn Oct 07 '15 at 12:49
  • Yes, I was a little worried about RadCharts not being supported any more, but I have everything up and running fine in my project and shouldn't need to make any changes going forwards. Thanks for you're help/suggestions! – Russ Dooley Oct 07 '15 at 14:42