I'd like to be able to advance through a Powerpoint presentation by pressing buttons in a Windows form. Here's some code I've found from http://bytes.com/topic/c-sharp/answers/272940-open-powerpoint-presentation-c-window-form that opens a Powerpoint presentation slide show:
Microsoft.Office.Interop.PowerPoint.Application oPPT;
Microsoft.Office.Interop.PowerPoint.Presentations objPresSet;
Microsoft.Office.Interop.PowerPoint.Presentation objPres;
//the location of your powerpoint presentation
string strPres = #"filepath";
//Create an instance of PowerPoint.
oPPT = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
// Show PowerPoint to the user.
oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
objPresSet = oPPT.Presentations;
//open the presentation
objPres = objPresSet.Open(strPres, MsoTriState.msoFalse,
MsoTriState.msoTrue, MsoTriState.msoTrue);
objPres.SlideShowSettings.Run();
I haven't found any methods that can advance through the slides, however. Any ideas?
(Really what I'm trying to do is use the WiiRemote to advance the slides, for a student project).
The method to advance programatically is "SlideShowWindow.View.Next". You can also use "SlideShowWindow.View.Previous" to go backwards.
Looks like there is a method called GotoSlide that will work, just needed to dig a little more! For instance:
int i = 0;
while (true)
{
i++;
objPres.SlideShowWindow.View.GotoSlide(i, MsoTriState.msoFalse);
System.Threading.Thread.Sleep(5000);
}
I think you could do this to run them one at a time, for instance:
oSettings = objPres.SlideShowSettings
oSettings.StartingSlide = 3
oSettings.EndingSlide = 3
oSettings.Run()
Do While oApp.SlideShowWindows.Count >= 1
System.Windows.Forms.Application.DoEvents()
Loop
You might have get a answer for you question, However for the people who will face the same kind of problem I will send a link for a opensource C# code which handles this kind of situation smoothly.
https://code.msdn.microsoft.com/office/How-to-Automate-control-23cd2a8f
Download the zip file, inside there is a c# project which controls power point slides perfectly
Best wishes folks.
Related
I'm using Microsoft.Office.Interop.PowerPoint library to open and view a PowerPoint file. I'm opening the file as an SlideShow without problems. The code to open the file is the following:
Microsoft.Office.Interop.PowerPoint.Application _pptApp;
Microsoft.Office.Interop.PowerPoint.Presentation _ppt;
Microsoft.Office.Interop.PowerPoint.Presentations _pptPresentations;
Microsoft.Office.Interop.PowerPoint.SlideShowWindow _pptSlideShowWindow;
private void Open(string fileName)
{
_pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
_pptPresentations = _pptApp.Presentations;
//fileName represents the full path of the file
_ppt = _pptPresentations.Open(fileName, Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse);
_ppt.SlideShowSettings.ShowPresenterView = Microsoft.Office.Core.MsoTriState.msoFalse;
_ppt.SlideShowSettings.ShowType = Microsoft.Office.Interop.PowerPoint.PpSlideShowType.ppShowTypeSpeaker;
_pptSlideShowWindow = _ppt.SlideShowSettings.Run();
}
The code above works fine. With the _pptSlideShowWindow I can do some operations, like go to next slide _pptSlideShowWindow.View.Next(); or go to previous slide _pptSlideShowWindow.View.Previous();.
I would like to Zoom in and zoom out the presentations while it is on SlideShow. I've been looking around and I haven't seen any solution that works for me. The SlideShowView has a Zoom property but it's read only:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slideshowview.zoom.aspx
I've tried not to open as SlideShow but the result is not good, as I haven't managed to open the file in reading mode programatically.
I'm a bit lost with this. Any help with this will be really appreciated.
Regards,
Pau
I have been struggling with C# and PowerPoint, I posted earlier about how to update Links in ppt using C# if the links were set to manual, I didn't get any responses so I figured I would try to circumvent the issue by setting the links to automatic in the file, then when C# opens it it updates them, saves the file, and then breaks them and saves it as another file name, but that hasn't proven any easier.
All I need to know is how to break the links. I know some VBA and wrote a code to break them, but when I call a macro in C# with a RunMacro method it doesn't seem to be working with the method I am using (? - I'm new to C# so I don't fully understand why this is, but if you Google "run macro PowerPoint C#" you will find the way I am sure I tried to go about it.) Please help, I am at a complete loss.
My script looks something like this
Using PowerPoint = Microsoft.Office.Interop.PowerPoint;
public void Main()
{
PowerPoint.Application ppt = new PowerPoint.Application();
PowerPoint.Presentation PRS = ppt.Presentations.Open(#"Filename.pptm",
Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
PRS.UpdateLinks();
PRS.Save
//here is where I need to break the links
PRS.SaveAs(#"filename with links broken.pptm",
Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentationMacroEnabled, MsoTriState.msoTrue);
PRS.Close();
ppt.Quit();
}
I tried setting the linkformat to manual before opening the file, but that doesn't affect any shapes that are already created, only new ones created within the program afterwards.
I have done a similar project in Powerpoint which also involves breaking links. In my program I am reading from an Excel file and take this data and put it into a Powerpoint presentation. In my Powerpoint template file I have all of my links to my Excel file laid out and formatted the way that I want it to look. The program begins to run and this fills the Excel file. After the writing to Excel is finished, I open up Powerpoint and UpdateLinks() to my presentation. Once the links are updated I break the links using a for loop on the Shapes in the Powerpoint. After, I save and close the document. Below is my function that I use to create my Powerpoint file based off of each of my ppt file templates (for my example I iterate through multiple ppt files because each ppt file contains only one slide. They are all combined into one slideshow later in the process).
public void CreatePowerpoint()
{
string[] fileArray = Directory.GetFiles(#"C:\Users\Me\Desktop\test");
Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
for (int i = 0; i < fileArray.Length; i++)
{
string file = fileArray[i];
Microsoft.Office.Interop.PowerPoint.Presentation powerpoint = pptApp.Presentations.Open(file);
powerpoint.UpdateLinks();
Microsoft.Office.Interop.PowerPoint.Slides slides = powerpoint.Slides;
Microsoft.Office.Interop.PowerPoint.Slide slide = slides[1];
Microsoft.Office.Interop.PowerPoint.Shapes pptShapes = (Microsoft.Office.Interop.PowerPoint.Shapes)slide.Shapes;
foreach (Microsoft.Office.Interop.PowerPoint.Shape y in pptShapes)
{
Microsoft.Office.Interop.PowerPoint.Shape j = (Microsoft.Office.Interop.PowerPoint.Shape)y;
try
{
//If auto link update is disabled for links
//j.LinkFormat.j.Update();
if (j.LinkFormat != null)
{
j.LinkFormat.BreakLink();
}
}
catch (Exception)
{
}
}
powerpoint.SaveAs(#"C:\Users\Me\Desktop\test" + i + ".pptx");
powerpoint.Close();
Thread.Sleep(3000);
}
pptApp.Quit();
}
Changing things before opening a file will have no effect on files that aren't open, of course. Iterate through the shapes collection on each slide and for each shape:
If .Type = msoLinkedOLEObject Then
.LinkFormat.BreakLink
End If
msoLinkedOLEObject = 10
I've spent three weeks googling it, and I -have- found snippets, but none of them have been useful. I'm trying to write a c# program that is able to view a powerpoint. I have no idea how. I've looked through SO many snippets and the MSDN pages in the Ppt interop and I'm completely at a loss. Has anybody done this, or knows how and would quickly demonstrate code showing me how to do this? As little code as needed to get it working would be preferrable. What I'm going for is this: A powerpoint slide is going to be displayed in a picturebox and every 40 seconds it's going to switch to the next slide. I am NOT allowed to export the powerpoints to pictures, and load the pictures (Which I couldn't figure out how to do, either). If anybodys wondering, yes this IS for a programming class, however it's not a graded assignment. I've spent three weeks on this and it's driving me insane. Any help at all would be appreciated. Thank you. If it helps, here's all the working code I've come up with on my own so far, and it's nothing like what I'm trying to accomplish.
PowerPoint.Application oPPT;
PowerPoint.Presentations objPresSet;
const string strPres = #"E:\C#\Ch 16\PP Stuff\TestTextBox\TextBoxTestWithArrays\TextBoxTestWithArrays\Ad Analysis.pptx";
const string myPath = #"E:\C#\Ch 16\PP Stuff\TestTextBox\TextBoxTestWithArrays\TextBoxTestWithArrays\";
{
oPPT = new PowerPoint.Application();
oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
objPresSet = oPPT.Presentations;
objPresSet.Open(strPres, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
/*
* This crashes, and I'm clueless as to why it wouldn't work. I wanted it here
* to check the # of msg boxes that opened against the # of slides in the ppt.
*/
foreach (PowerPoint.Slides mySlides in objPresSet)
MessageBox.Show("{0}", mySlides.ToString());
}
Have a look at http://skp.mvps.org/vb/pptvbwnd.htm
It explains how to display and control a presentation on form in VB5/6, but might give you some ideas.
I have a C# application that When the user clicks Print the application creates a PDF in memorystream using ITextSharp. I need to print this PDF automatically to a specific printer and tray.
I have searched for this but all i can find is using javascript, but it doesn't print to a specific tray.
Does anyone have an examples of doing this?
Thank you.
You can change printer tray with this code.
string _paperSource = "TRAY 2"; // Printer Tray
string _paperName = "8x17"; // Printer paper name
//Tested code comment. The commented code was the one I tested, but when
//I was writing the post I realized that could be done with less code.
//PaperSize pSize = new PaperSize() //Tested code :)
//PaperSource pSource = new PaperSource(); //Tested code :)
/// Find selected paperSource and paperName.
foreach (PaperSource _pSource in printDoc.PrinterSettings.PaperSources)
if (_pSource.SourceName.ToUpper() == _paperSource.ToUpper())
{
printDoc.DefaultPageSettings.PaperSource = _pSource;
//pSource = _pSource; //Tested code :)
break;
}
foreach (PaperSize _pSize in printDoc.PrinterSettings.PaperSizes)
if (_pSize.PaperName.ToUpper() == _paperName.ToUpper())
{
printDoc.DefaultPageSettings.PaperSize = _pSize;
//pSize = _pSize; //Tested code :)
break;
}
//printDoc.DefaultPageSettings.PaperSize = pSize; //Tested code :)
//printDoc.DefaultPageSettings.PaperSource = pSource; //Tested code :)
in the past I spent a lot of time searching the web for solutions to print pdf files to specific printer trays.
My requirement was: collect several pdf files from server directory and send each file to a different printer tray in a loop.
So I have tested a lot of 3rd party tools (trials) and best practices found in web.
Generally all theese tools can be divide into two classifications: a) send pdf files to printer in a direct way (silent in UI) or b) open pdf files in UI using a built-in pdf previewer working with .Net-PrintDocument.
The only solution that fix my requirement was PDFPrint from veryPdf (drawback: it´s not priceless, but my company bought it). All the other tools and solutions didn´t work reliable, that means: calling their print-routines with parameter e.g. id = 258 (defines tray 2; getting from installed printer) but printing the pdf file in tray 3 or pdf was opened in print previewer (UI) with lost images or totally blank content and so on..
Hope that helps a little bit.
There is a tool called pdfprint:
http://www.verypdf.com/pdfprint/index.html
And here they discuss some solutions:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/da99765f-2706-4bb6-aa0e-b90730294cb4
I am currently trying to change some settings in a .pptx files via C# and Microsoft.Office.Interop.PowerPoint. I have some .wmv movies linked on several slides of the presentation. At the time the presentations were created, all movies play as soon as they are clicked. However, I want to change this to start automatically playing as soon as the slide is viewed. This this has to be done to a lot of presentations, so there is no way to do this manually.
I found the PlaySettings.PlayOnEntry property, but I can't figure out how to use it. I found several examples how to do this with a new movie to be embedded (and then, only for Visual Basic), but since the movies are already embedded, this is not what I want.
I also have no idea how I can actually access any objects on the current slide, maybe there is a way to check if a shape is a video-file and then change above setting, but the MSDN-Reference is not very helpful on Office-Topics. I'm using Powerpoint 2007 and Visual Studio 2010 if that matters.
#Lennart's solution is part of it, you then need a page trigger
var videoAnimation = slide.TimeLine.MainSequence.FindFirstAnimationFor(objShapes);
if (videoAnimation != null)
{
videoAnimation.Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
}
Got it. Searching through all shapes of the Presentation and filtering out the movies works:
//While iterating through all slides i:
objShapes = objPres.Slides[i].Shapes;
foreach (Microsoft.Office.Interop.PowerPoint.Shape s in objShapes) {
if(s.Name.Contains(".wmv")){
s.AnimationSettings.PlaySettings.PlayOnEntry = MsoTriState.msoTrue;
}
}