You must Sign In to post a response.
  • Category: ASP.NET

    Create power point slide and charts using c#.net

    Hi, I have created an application which can generate a power point presentation. The main concern about this is creating a slide on fly and drawing the charts on it. I have accomplished this task, now my problem is the charts which i have drawn is not perfect according to my client. those charts need to draw with relative comparision of other charts on the slide. So i tried to change the height of the chart, which affects the width too. When i tried with width there is no changes.



    look into my code and suggest me, i have a template for my chart that means how it should look like. If any one is thr to help me out than i can mail u my template. Thanx in advance.



    using System;

    using System.Collections;

    using System.Configuration;

    using System.Data;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.HtmlControls;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using PowerPoint;

    using Graph;

    using Microsoft.Office.Core;



    private static PowerPoint.Presentation _pPres = null;

    private static PowerPoint.ApplicationClass _pApp = null;

    private int noofSalespersons;



    protected void Page_Load(object sender, EventArgs e)

    {

    _pApp = new ApplicationClass();

    //Graph.Chart objChart;

    int noofSlides;

    noofSalespersons =12;

    string sTemplateFile = Server.MapPath("Resource\\Template.ppt");

    _pPres = _pApp.Presentations.Open(sTemplateFile, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);

    noofSlides = (noofSalespersons / 10) + 1;

    if (noofSalespersons%10>0)

    {

    noofSlides += 1;

    }

    int slideIndex=1;

    while (_pPres.Slides.Count!=noofSlides)

    {

    _pPres.Slides.InsertFromFile("D:\\Template.ppt", slideIndex, 1, 1);

    slideIndex += 1;

    }


    Chart chart;

    Graph.DataSheet dataSheet;

    for (int i = 1; i <= slideIndex; i++)

    {

    PowerPoint.Slide slide = _pPres.Slides._Index(i) as Slide;

    if (i==1)

    {

    PowerPoint.Shape shape = slide.Shapes[1];


    chart = shape.OLEFormat.Object as Graph.Chart;

    dataSheet = chart.Application.DataSheet;

    dataSheet.Cells[2, 2] = "50";

    dataSheet.Cells[2, 3] = "40";

    dataSheet.Cells[2, 4] = "50";

    dataSheet.Cells[2, 5] = "50";

    dataSheet.Cells[3, 2] = "60";

    dataSheet.Cells[3, 3] = "70";

    dataSheet.Cells[3, 4] = "80";

    dataSheet.Cells[3, 5] = "60";

    //dataSheet.Cells[3, 6] = "0";

    dataSheet.Cells[4, 2] = "50";

    dataSheet.Cells[4, 3] = "40";

    dataSheet.Cells[4, 4] = "50";

    dataSheet.Cells[4, 5] = "50";

    //dataSheet.Cells[4, 6] = "0";

    chart.Application.Update();

    dataSheet = null;

    chart = null;

    }

    ArrayList listShapeName = new ArrayList();

    ArrayList listAutoShapes = new ArrayList();

    ArrayList listTextBox = new ArrayList();

    ArrayList listPlaceHolder = new ArrayList();

    int reminingShapes;

    reminingShapes = noofSalespersons % 10;

    if (i>=2)

    {

    if ((i == slideIndex) && (reminingShapes>0))

    {

    int remingCount = 0;

    for (int k = 1; k <= slide.Shapes.Count; k++)

    {

    PowerPoint.Shape shape = slide.Shapes[k];

    //string shapeName = shape.Name;

    //listShapeName.Add(shapeName);

    if (shape.Type == MsoShapeType.msoEmbeddedOLEObject)

    {

    remingCount += 1;

    if (remingCount>reminingShapes)

    {

    //slide.Shapes[k].Delete();

    listShapeName.Add(k);

    }

    }

    }

    for (int m = listShapeName.Count - 1; m >= 0; m--)

    {

    slide.Shapes[listShapeName[m]].Delete();

    }

    listShapeName.Clear();

    for (int k = 1; k <= slide.Shapes.Count; k++)

    {

    PowerPoint.Shape shape = slide.Shapes[k];


    if (reminingShapes < 6)

    {

    if (shape.Type == MsoShapeType.msoTextBox)

    {

    listTextBox.Add(k);

    }

    }

    }

    if (listTextBox.Count>0)

    {

    for (int m = listTextBox.Count - 1; m >= listTextBox.Count - 4; m--)

    {

    slide.Shapes[listTextBox[m]].Delete();

    }

    listTextBox.Clear();

    }


    for (int k = 1; k <= slide.Shapes.Count; k++)

    {

    PowerPoint.Shape shape = slide.Shapes[k];

    if (reminingShapes < 6)

    {

    if (shape.Type == MsoShapeType.msoAutoShape)

    {

    listAutoShapes.Add(k);

    }

    }

    }

    if (listAutoShapes.Count>0)

    {

    for (int m = listAutoShapes.Count - 1; m >= listAutoShapes.Count - 4; m--)

    {

    slide.Shapes[listAutoShapes[m]].Delete();

    }

    listAutoShapes.Clear();

    }

    }

    int z = 0;

    int bottom = 0;

    for (int k = 1; k <= slide.Shapes.Count; k++)

    {

    PowerPoint.Shape shape = slide.Shapes[k];

    string shapeName= shape.Name;

    if (shape.Type==MsoShapeType.msoEmbeddedOLEObject)

    {

    listShapeName.Add(shapeName);


    chart =shape.OLEFormat.Object as Graph.Chart;

    dataSheet = chart.Application.DataSheet;

    //if (k % 2 == 0)

    //{

    z = z + 1;


    //shape.Top = newHeight;

    //shape.IncrementTop(200);//(200-shape.Height) + shape.Top);

    shape.Height = ((42 - (2 * z)) * 200) / (40);

    //shape.Width = 90;

    dataSheet.Cells[2, 2] = (((11-z) * 100) / 100).ToString();

    dataSheet.Cells[3, 2] = (((11-z) * 100) / 100).ToString();

    dataSheet.Cells[4, 2] = (((11-z) * 100) / 100).ToString();

    dataSheet.Cells[5, 2] = (((11-z) * 100) / 100).ToString();

    //shape.Width = 90;


    //}

    //else

    //{


    // //shape.Width = 86;

    // shape.Height = 200;

    // //newHeight = shape.Top;

    // dataSheet.Cells[2, 2] = ((80 * 100) / 260).ToString();

    // dataSheet.Cells[3, 2] = ((70 * 100) / 260).ToString();

    // dataSheet.Cells[4, 2] = ((60 * 100) / 260).ToString();

    // dataSheet.Cells[5, 2] = ((50 * 100) / 260).ToString();

    //}

    chart.Application.Update();

    dataSheet = null;

    chart = null;

    }

    }




    }

    _pPres.SaveAs("d:\\Vijay\\Powerpoint\\Sample2.ppt", PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse);

    _pPres.Close();

    _pApp.Quit();

    GC.Collect();


    }
  • #259779
    Hi,

    You can use .Net 2008 .It will support Ms Office,Powerpoint, Excel inbuilt integeration with .Net framework 3.5 .

    You can easily create power point slides in .Net 2008.

    Thanks and Regards
    S.S.Bajoria


    Thanks & Regards


    Bunty

  • #765413
    is that code really works
    i m got some problem with that application class
    can u help me out in it.


    Regards
    Ankit

  • #765417
    Here is a sample which demonstrates create ppt and insert chart in c# and vb.net , it's based on a free .net ppt library, hope this could gives you an idea:
    https://code.msdn.microsoft.com/Insert-Chart-to-PowerPoint-0c2c848b/

  • #765423
    Mr. Michael
    Did you work on it.?

  • #765424
    Mr. Michael
    Did you work on it.?
    i m stuck at Spire.Presentation dll

    regards
    Ankit

  • #765474
    Yes, what can I help you? What's the problem? In addition, you can post your issue to the Spire.Presentation forum: http://www.e-iceblue.com/forum/spire-presentation-f14.html


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.