Monthly Archives :

September 2014

C# ile Powerpoint Sunumu Hazırlamak 554 382 mezo

C# ile Powerpoint Sunumu Hazırlamak

Merhaba arkadaşlar
Uzun süreden beri bir makale yazmaya vakit bulamıyorum ama yavaş yavaş geri dönüyorum. Bu yazıda sizlere zevkli küçük bir örnek göstermek istiyorum. 😀 C# üzerinden program yardımı ile PowerPoint sunumu hazırlamanın nasıl olduğu ile ilgili başlangıçta çok işinize yarayacak bir kod parçası
Bunun için öncelikle bir windows Forms projesi açalım ve 1 tane Buton ekleyelim 🙂 Projemiz içersine Referans olarak 2 önemli kütüphane eklememiz gerekiyor. Sağa tıklayıp “Add Reference” dedikten sonra “COM” sekmesi içersinde bulunan microsoft graph 15.0 object library ve microsoft PowerPoint 15.0 object library kütüphanelerini seçip ekleyelim.
Artık gerisi çok kolay 🙂 işte bundan sonra işi yapacak olan kod parçası

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;

namespace testToCreatePttFileFromImages
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string pictureFileName = “C:\\picToVideo\\2.jpg”;

Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.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);

// Add title
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = “The Header Of The Presentation”;
objText.Font.Name = “Arial”;
objText.Font.Size = 32;

//objText = slide.Shapes[2].TextFrame.TextRange;
//objText.Text = “this text come after the heading with bullet”;

Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
slide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

//slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = “the text is for the notes to specific page”;

pptPresentation.SaveAs(@”c:\picToVideo\fppt.pptx”, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
pptPresentation.Close();
pptApplication.Quit();

}
}
}

    Join our Newsletter

    We'll send you newsletters with news, tips & tricks. No spams here.