IT Community - Software Programming, Web Development and Technical Support

How to create PowerPoint Document in C#?

This is a discussion on How to create PowerPoint Document in C#? within the C# Programming forums, part of the Software Development category; Hi, I want to create a powerpoint document using C#. Is there any component available to do this?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-26-2007, 08:56 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default How to create PowerPoint Document in C#?

Hi,

I want to create a powerpoint document using C#. Is there any component available to do this?
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-26-2007, 09:00 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: How to create PowerPoint Document in C#?

Hi,

You can do this using a PowerPoint object type library and Graph and Microsoft.office.core library. Add these libraries as reference. Copy and paste the following code.

using Microsoft.Office.Core;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Graph = Microsoft.Office.Interop.Graph;
using System.Runtime.InteropServices;

String strTemplate, strPic;
strTemplate =
"C:\\Program Files\\Microsoft Office\\Templates\\Presentation Designs\\Blends.pot";
strPic = "C:\\Windows\\Blue Lace 16.bmp";
bool bAssistantOn;

PowerPoint.Application objApp;
PowerPoint.Presentations objPresSet;
PowerPoint._Presentation objPres;
PowerPoint.Slides objSlides;
PowerPoint._Slide objSlide;
PowerPoint.TextRange objTextRng;
PowerPoint.Shapes objShapes;
PowerPoint.Shape objShape;
PowerPoint.SlideShowWindows objSSWs;
PowerPoint.SlideShowTransition objSST;
PowerPoint.SlideShowSettings objSSS;
PowerPoint.SlideRange objSldRng;
Graph.Chart objChart;

//Create a new presentation based on a template.
objApp = new PowerPoint.Application();
objApp.Visible = MsoTriState.msoTrue;
objPresSet = objApp.Presentations;
objPres = objPresSet.Open(strTemplate,
MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
objSlides = objPres.Slides;

//Build Slide #1:
//Add text to the slide, change the font and insert/position a
//picture on the first slide.
objSlide = objSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
objTextRng.Text = "My Sample Presentation";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
objSlide.Shapes.AddPicture(strPic, MsoTriState.msoFalse, MsoTriState.msoTrue,
150, 150, 500, 350);

//Build Slide #2:
//Add text to the slide title, format the text. Also add a chart to the
//slide and change the chart type to a 3D pie chart.
objSlide = objSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
objTextRng.Text = "My Chart";
objTextRng.Font.Name = "Comic Sans MS";
objTextRng.Font.Size = 48;
objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320,
"MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "",
MsoTriState.msoFalse).OLEFormat.Object;
objChart.ChartType = Graph.XlChartType.xl3DPie;
objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom;
objChart.HasTitle = true;
objChart.ChartTitle.Text = "Here it is...";

//Build Slide #3:
//Change the background color of this slide only. Add a text effect to the slide
//and apply various color schemes and shadows to the text effect.
objSlide = objSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank);
objSlide.FollowMasterBackground = MsoTriState.msoFalse;
objShapes = objSlide.Shapes;
objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTex tEffect27,
"The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

//Modify the slide show transition settings for all 3 slides in
//the presentation.
int[] SlideIdx = new int[3];
for (int i = 0; i < 3; i++) SlideIdx[i] = i + 1;
objSldRng = objSlides.Range(SlideIdx);
objSST = objSldRng.SlideShowTransition;
objSST.AdvanceOnTime = MsoTriState.msoTrue;
objSST.AdvanceTime = 3;
objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut;

//Prevent Office Assistant from displaying alert messages:
bAssistantOn = objApp.Assistant.On;
objApp.Assistant.On = false;

//Run the Slide show from slides 1 thru 3.
objSSS = objPres.SlideShowSettings;
objSSS.StartingSlide = 1;
objSSS.EndingSlide = 3;
objSSS.Run();

//Wait for the slide show to end.
objSSWs = objApp.SlideShowWindows;
while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);

//Reenable Office Assisant, if it was on:
if (bAssistantOn)
{
objApp.Assistant.On = true;
objApp.Assistant.Visible = false;
}

//Close the presentation without saving changes and quit PowerPoint.
objPres.Close();
objApp.Quit();

Thanks..

S.Balasubramanian..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is here document in PHP? Jeyaseelansarc PHP Programming 14 04-08-2008 07:18 PM
document.write iframes S.Vinothkumar HTML, CSS and Javascript Coding Techniques 8 11-28-2007 02:21 AM
How to convert a word document/text document/PDF file into an image file? kingmaker C# Programming 0 07-16-2007 11:23 PM
Rules that must be followed by an XML document vigneshgets XML and SOAP 1 07-11-2007 07:39 AM
Javascript Document Object Jeyaseelansarc HTML, CSS and Javascript Coding Techniques 0 05-21-2007 07:48 AM


All times are GMT -7. The time now is 11:05 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0