// Test driver. public static bool Test() { bool passed = true; PowerPoint.Application app = new PowerPoint.Application(); //PowerPoint.Application app = new PowerPoint.ApplicationClass(); app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; PowerPoint.Presentation presentation = app.Presentations.Add(Core.MsoTriState.msoFalse); PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); PowerPoint.Shape shape = slide.Shapes.AddLine(0, 0, 100, 100); Console.WriteLine("Test on presentation."); passed = passed && TestTags(presentation.Tags); Console.WriteLine("Test on slide."); passed = passed && TestTags(slide.Tags); Console.WriteLine("Test on shape."); passed = passed && TestTags(shape.Tags); app = null; return(passed); }
public void checkin(PowerPoint.Presentation presentationDocument) { try { if (MessageBox.Show(resources.GetString("sure_check_in"), resources.GetString("checkin"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { String localFileName = presentationDocument.FullName; presentationDocument.Save(); // save document presentationDocument.Close(); // close document docXML.refresh(); // Refresh document list if (docXML.isOpenKMDocument(localFileName)) { OKMDocument oKMDocument = docXML.getOpenKMDocument(localFileName); docXML.remove(oKMDocument); DocumentLogic.checkin(oKMDocument, configXML.getHost(), configXML.getUser(), configXML.getPassword()); if (File.Exists(localFileName)) { File.Delete(localFileName); } } } } catch (Exception e) { String errorMsg = "OpenKMPowerPointAddIn - (checkinButton_Click)\n" + e.Message + "\n\n" + e.StackTrace; MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static PowerPoint.Presentation OpenDocument(string documentPath) { InitializeInstance(); PowerPoint.Presentation powerPointDoc = powerPointApp.Presentations.Open(documentPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); return(powerPointDoc); }
public static void CloseDocument(PowerPoint.Presentation powerPointDoc) { if (powerPointDoc != null) { powerPointDoc.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(powerPointDoc); powerPointDoc = null; } }
private void NavigateComplete2(object sender, AxIEBrowser._IIEBrowserCtlEvents_NavigateCompleteEvent e) { object o = e.document; object oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null); _presentation = (PowerPoint.Presentation)oDocument; _navigateComplete = true; if (_highlightWords == true) { HighlightWords(); _navigateComplete = false; _highlightWords = false; } }
// Show tree form public void showTreeForm(PowerPoint.Presentation presentation) { try { presentation.Save(); // Saves the document if (treeForm == null) { treeForm = new TreeForm(presentation.FullName, configXML); } else { treeForm.setApplication(presentation.FullName); } treeForm.Show(); treeForm.startUp(); } catch (Exception e) { throw e; } }
private Boolean ppt_exec(OfficeDomain office) { Boolean result = false; if (Array.IndexOf(ppt, office.prefix) > -1) { log("ppt开始工作..."); PowerPoint.Presentation presentation = null; try { //参数含义:路径、只读 presentation = pptApp.Presentations.Open(office.path, PowerPoint.MsoTriState.msoTrue); //转换 presentation.ExportAsFixedFormat(office.pdfFileName, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen); result = true; log("ppt工作完毕,准备关闭文件.."); } catch (Exception e) { error("ppt工作异常:{0}", e.Message); } finally { if (presentation != null) { try { presentation.Close(); log("ppt文件成功关闭.."); } catch (Exception e) { error("ppt关闭文件时发生错误{1},重启{0}.exe", ppt_name, e.Message); ppt_start(); } } } } return(result); }
private string GetDocumentText(object path) { StringBuilder result = new StringBuilder(); try { InitializePowerPoint(); if (_powerPoint != null) { PowerPoint.Presentation presentation = _powerPoint.Presentations.Open((string)path, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); PowerPoint.Slides slides = presentation.Slides; int count = slides.Count; foreach (PowerPoint.Slide slide in slides) { PowerPoint.Shapes shapes = slide.Shapes; count = shapes.Count; foreach (PowerPoint.Shape shape in shapes) { if (shape.HasTextFrame == MsoTriState.msoTrue) { result.Append(shape.TextFrame.TextRange.Text).Append(" "); } } //foreach ( PowerPoint.Comment comment in slide.Comments ) //{ //comment.Text; //} } } } catch (Exception exception) { _tracer.TraceException(exception); } ShutdownPowerPoint( ); return(result.ToString()); }
public bool GetOpenPpt() { bool success = false; try { // Get Running PowerPoint Application object pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PowerPoint.Application; } catch { } if (pptApplication != null) { success = true; // Get Presentation Object presentation = pptApplication.ActivePresentation; // Get Slide collection object slides = presentation.Slides; // Get Slide count slidesCount = slides.Count; // Get current selected slide try { // Get selected slide object in normal view slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber]; } catch { // Get selected slide object in reading view slide = pptApplication.SlideShowWindows[1].View.Slide; } } return(success); }
}//end constructor for pptcontrol #endregion #region Small Helper Functions /// <summary> /// initPres initializes the current presentation and slide /// </summary> /// <returns>always returns true, showing presentation is initialized</returns> private bool initPres() { pptPres = pptApp.ActivePresentation; presSlides = pptPres.Slides; return(true); }