How to get Telerik RadHtmlChart into PowerPoint presentation

343 views Asked by At

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

There are 2 answers

3
rdmptn On BEST ANSWER

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:

0
Russ Dooley On

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!