Archive

Posts Tagged ‘Office Interoperability’

Covert PowerPoint Slides to Images

October 9th, 2009 Anuraj P No comments

Today one of my colleague comes with a problem; he want to display a Powerpoint presentation in his Sharepoint site. But we didn’t got any direct way to display it. They we tweaked the code, to export the Slides to images and display it using the a custom slideshow web part, like the AjaxToolkit slideshow control.

I am attaching the code to export all the slides from a Power Point to Images

string ExportLocation = "C:\\Sample";
Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
ppApp.Visible = MsoTriState.msoTrue;
ppApp.WindowState = PpWindowState.ppWindowMinimized;
Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open("C:\\ScreenShots.ppt",
            MsoTriState.msoFalse, MsoTriState.msoFalse,
            MsoTriState.msoFalse);
ppApp.ShowWindowsInTaskbar = MsoTriState.msoFalse;	//Hiding the application; But it will be displayed always
try
{
    Slides objSlides = oPres.Slides;	//Getting all the slides
    for (int i = 1; i < objSlides.Count - 1; i++)
    {
        string file = Path.Combine(ExportLocation, string.Format("{0}.{1}", objSlides[i].Name, "jpg"));
        oPres.Slides[i].Export(file, "jpg", 800, 600);
    }
}
finally
{
    ppApp.Quit();	//Closing the Powerpoint application. Sometimes it won't work too.
}

Thanks to ArunKumar, for providing the code snippet.

Calling word Macros from .Net

September 20th, 2007 Anuraj P No comments

While using Word automation with .Net sometimes it is required ti call, word macro’s from C# or VB.Net.

Here is the code to call word macros from VB.Net.

Dim WordApp As New Microsoft.Office.Interop.Word.Application
CType(WordApp, Object).GetType().InvokeMember("Run", Reflection.BindingFlags.Default Or Reflection.BindingFlags.InvokeMethod, Nothing, CType(WordApp, Object), New Object() {"helloworld"})

In the code, helloworld is the macro name.Or you can simply call WordApp.Run("helloworld") will also works fine.

 

You can also refer link from Microsoft
http://support.microsoft.com/kb/306683