private void DeleteSlide(int index) { //TODO: try-catch PPT.Application app = new PPT.Application(); PPT.Presentations pres = app.Presentations; PPT.Presentation pptx = pres.Open(LibraryFile.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); PPT.Slides slides = pptx.Slides; PPT.Slide slide = slides[index]; slide.Delete(); pptx.Save(); pptx.Close(); slide.ReleaseCOM(); slide = null; slides.ReleaseCOM(); slides = null; pptx.ReleaseCOM(); pptx = null; pres.ReleaseCOM(); pres = null; app.ReleaseCOM(); app = null; }
internal static Boolean CheckObjectsExist() { PowerPoint.Slides slides = Globals.ThisAddIn.Application.ActivePresentation.Slides; foreach (PowerPoint.Slide slide in slides) { PowerPoint.Slide currSlide = slides[slide.SlideIndex]; foreach (PowerPoint.Shape shape in currSlide.Shapes) { if (shape.Type.Equals(Office.MsoShapeType.msoTextBox)) { if (shape.TextFrame.TextRange.Font.Color.RGB.Equals(9109675)) { return(true); } } else if (shape.Type.Equals(Office.MsoShapeType.msoInkComment)) { if (shape.Line.ForeColor.RGB.Equals(9109675)) { return(true); } } } } return(false); }
public void OpenPPT(string pptPath) { // 必须先运行幻灯片,下面才能获得PowerPoint应用程序,否则会出现异常 // 获得正在运行的PowerPoint应用程序 try { pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPt.Application; } catch { MessageBox.Show("启动幻灯片失败", "Error", MessageBoxButtons.OKCancel); } if (pptApplication != null) { try { // 在普通视图下这种方式可以获得当前选中的幻灯片对象 // 然而在阅读模式下,这种方式会出现异常 // 获得当前选中的幻灯片 is_open = true; Thread.Sleep(2000); //获得演示文稿对象 presentation = pptApplication.ActivePresentation; // 获得幻灯片对象集合 slides = presentation.Slides; // 获得幻灯片的数量 slidescount = slides.Count; slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber]; } catch { slide = pptApplication.SlideShowWindows[1].View.Slide; } } }
private void button_Connect_Click(object sender, EventArgs e) { try { pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPT.Application; presentation = pptApplication.ActivePresentation; slides = presentation.Slides; slidescount = slides.Count; 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; } powercon = true; button_Connect.Text = "Powerpoint Connected"; button_Connect.Enabled = false; } catch { MetroFramework.MetroMessageBox.Show(this, "Please check PowerPoint is running.", "Maestro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//To create ppt with generated .gif files private void CreatePPT(string sruninFileName) { string sTemplatePPTPath = Utility.m_sBinPath + "Template.pptm"; string sNewPPTPath = Utility.m_sOutputFolderPath + "" + sruninFileName + ".pptm"; try { string[] sFiles = System.IO.Directory.GetFiles(Utility.m_sOutputFolderPath, "*.gif"); if (System.IO.File.Exists(sTemplatePPTPath)) { System.IO.File.Copy(sTemplatePPTPath, sNewPPTPath, true); Powerpoint.Application pptApp = new Powerpoint.Application(); Powerpoint.Presentation presentation = pptApp.Presentations.Open(sNewPPTPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue); Powerpoint.Slides oSlides = presentation.Slides; for (int i = 0; i < sFiles.Length; i++) { int slide_index = i + 2; Powerpoint.Slide oSlide = (Powerpoint.Slide)presentation.Slides._Index(slide_index); Powerpoint.CustomLayout oLayout = (Powerpoint.CustomLayout)oSlide.CustomLayout; pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Powerpoint.Slide oNewSlide = presentation.Slides.AddSlide(slide_index + 1, oLayout); oNewSlide.Shapes.AddPicture(sFiles[i], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 86, 688, 401); } presentation.Save(); } else { MessageBox.Show(sTemplatePPTPath + " file doesn't exists in this path"); } } catch (Exception ee) { Utility.WriteErrorLog(ee); } }
public void PptAction(PptDetails pptDetails) { pptDetailsMain = pptDetails; DodoMediaPlayer.Stop(); this.Hide(); if (pptDetails != null) { try { //Create a new presentation based on a template. objApp = new powerpointinterop.Application(); // objApp.SlideShowBegin += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowBeginEventHandler(powerpnt_SlideShowBegin); objApp.SlideShowEnd += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowEndEventHandler(powerpnt_SlideShowEnd); //objApp.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(powerpnt_SlideShowNextSlide); objApp.Visible = MsoTriState.msoTrue; objPresSet = objApp.Presentations; string pptName = pptDetails.Name; string pptPath = System.IO.Path.Combine(Mocker.debugPath, "Ppts", pptName); objPres = objPresSet.Open(pptPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue); objSlides = objPres.Slides; objSSS = objPres.SlideShowSettings; objSSS.Run(); } catch (Exception) { } } else { MessageBox.Show("Media Not Found"); } }
//methods ------------------------------------------ public void AllSlides(PowerPoint.Presentation presentation) { /* * Find the path * Iterat throw all slides */ SetPresentationPath(presentation.Path.ToString()); SetImagePath(GetImageFolder()); MDFormConverter MDForm = new MDFormConverter(); DeleteExistingSmartArtImages(); PowerPoint.Slides slides = presentation.Slides; // just for texting and output string textmain = ""; string textShortDesc = ""; string textLongDesc = ""; foreach (PowerPoint.Slide slide in slides) { textmain += MDForm.GetNumberform(slide.SlideNumber, true); // get all shapes and test for type int smartArtNrPerSlide = 0; foreach (PowerPoint.Shape element in slide.Shapes) { // Documentation of MsoShapeType see https://msdn.microsoft.com/EN-US/library/ms251190 switch (element.Type) { case Office.MsoShapeType.msoSmartArt: // Get the Text ------------------------ smartArtNrPerSlide++; SmartArtInter smartArtInter = new SmartArtInter(); string title = MDForm.GetSmartArtTitle(element.SmartArt.Layout.Name, slide.SlideNumber, smartArtNrPerSlide); textShortDesc += title + "\r" + smartArtInter.GetSmartArtShortDescription(element) + "\n"; textLongDesc += title + "\r" + smartArtInter.GetSmartArtLongDescription(element) + "\n"; // Get the Image ----------------------- string imageName = "smartart_" + slide.SlideNumber.ToString() + "_" + smartArtNrPerSlide.ToString() + ".png"; string imagePath = GetImageFolder() + "\\" + imageName; element.Export(imagePath, PpShapeFormat.ppShapeFormatPNG, (int)presentation.PageSetup.SlideWidth, (int)presentation.PageSetup.SlideHeight, PpExportMode.ppScaleToFit); // Get the main Text ------------------- string titleID = title.Replace("## ", ""); titleID = titleID.Replace(" ", "-"); titleID = titleID.Replace("\n", ""); titleID = titleID.Replace(":", ""); titleID = titleID.ToLower(); textmain += MDForm.GetLinkToShortDesc(titleID); textmain += MDForm.GetLinkToLongDesc(IMAGEFOLDERNAME + "/" + imageName, titleID); break; default: break; } } SaveMDINFile(textmain, textShortDesc, textLongDesc); //System.Diagnostics.Debug.WriteLine(textShortDesc + textLongDesc); } }
public void Dispose() { if (_isDisposed) { return; } _isDisposed = true; if (_pptApplication != null) { _pptApplication.SlideShowBegin -= PptApplication_SlideShowBegin; _pptApplication.SlideShowEnd -= PptApplication_SlideShowEnd; _pptApplication.SlideShowNextSlide -= PptApplication_SlideShowNextSlide; //_pptApplication.Quit();此处不能用Quit,否则用户主动退出放映态时得不到事件通知 Marshal.ReleaseComObject(_presentation); Marshal.ReleaseComObject(_pptApplication); if (slide != null) { Marshal.ReleaseComObject(slide); } Marshal.ReleaseComObject(slides); _pptApplication = null; _presentation = null; slide = null; slides = null; } try { OnSlideShowEnd(); } catch (Exception) { //ignore } }
public void createFile(string filepath) { if (filepath.EndsWith(".xlsx")) { Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application(); Workbook ExcelWorkBook = null; ExcelApp.Visible = false; ExcelApp.DisplayAlerts = false; ExcelWorkBook = ExcelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); ExcelWorkBook.SaveAs(filepath); ExcelWorkBook.Close(); ExcelApp.Quit(); } else if (filepath.EndsWith(".pptx")) { Application pptApplication = new Application(); // 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]; Microsoft.Office.Interop.PowerPoint.Slides slides = pptPresentation.Slides; Microsoft.Office.Interop.PowerPoint.Slide slide = slides.AddSlide(1, customLayout); pptPresentation.SaveAs(filepath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue); pptPresentation.Close(); pptApplication.Quit(); } else { File.Create(filepath).Close(); } }
private void button_unlock_Click(object sender, EventArgs e) { this.savePptNum = 0; this.savepageNum = ppt[0].ActiveWindow.Selection.SlideRange.SlideNumber; //save와lock다른경우 if ((this.savepageNum != this.lockPageNum) || (this.savePptNum != this.lockPptNum)) { MessageBox.Show(lockPageNum + "의 slide를 수정완료먼저해주세요"); } else { string _Path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); presentation[this.savePptNum].Save(); PowerPoint.Application tempPpt = new PowerPoint.Application(); PowerPoint.Presentation tempPresentation = tempPpt.Presentations.Add(MsoTriState.msoFalse); PowerPoint.Slides tempSlides = tempPresentation.Slides; tempSlides.InsertFromFile(ButtonPPT[this.savePptNum].Tag.ToString(), 0, this.savepageNum, this.savepageNum); saveFileName = _Path + @"\" + "slide.pptx"; FileInfo fileInfo = new FileInfo(saveFileName); if (fileInfo.Exists == true) { File.Delete(this.saveFileName); } tempPresentation.SaveAs(_Path + @"\" + "slide"); this.askSave = true; } }
private void InitializePowerpointObjects() { m_pptApplication = new PowerPoint.Application(); m_pptPresCollection = m_pptApplication.Presentations; // Argument to choose whether the ppt is visible or not m_pptPres = m_pptPresCollection.Add(Office.MsoTriState.msoFalse); m_pptSlides = m_pptPres.Slides; }
/// <summary> /// 打开被选中的幻灯片 /// </summary> /// <param name="strTemplate"></param> private void ShowPresentation(string strTemplate) { objApp = new PowerPoint.Application(); objApp.Visible = MsoTriState.msoTrue; objPresSet = objApp.Presentations; objPres = objPresSet.Open(strTemplate, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objSlides = objPres.Slides; }
// //********************************************************************************************** // // Class TPPT // Part of : TDRFree // Function : Interacts with Microsoft Powerpoint to make a presentation // Author : Jan G. Wesseling // Date : April 9th, 2013 // //********************************************************************************************** // public TPPT() { MyApp = new PowerPoint.Application(); MyApp.Visible = MsoTriState.msoTrue; MyApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized; MyPresentations = MyApp.Presentations; MyPresentation = MyPresentations.Add(MsoTriState.msoFalse); MySlides = MyPresentation.Slides; }
private void Init() { //获得演示文稿对象 _presentation = _pptApplication.ActivePresentation; // 获得幻灯片对象集合 slides = _presentation.Slides; // 获得幻灯片的数量 PageCount = slides.Count; }
private static void PrepareDocument(PowerPoint.Presentation presentation, PowerPoint.Slides slides, COMObjectsHelper comHelper) { RemoveShapesWithEmptyTextFrame(slides, comHelper); RemoveSlides(slides, comHelper); if (slides.Count == 0) { CreateNewSlideWithEmptyShape(presentation, comHelper); } }
private void button2_Click(object sender, EventArgs e) { MessageBox.Show(this.textBox1.Text); PowerPoint.Slides slides = Globals.ThisAddIn.Application.ActivePresentation.Slides; PowerPoint.Slide slide = slides[1]; textbox = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 100, 600, 50); //向当前PPT添加文本框 textbox.TextFrame.TextRange.Text = this.textBox1.Text; //设置文本框的内容 textbox.TextFrame.TextRange.Font.Size = 48; //设置文本字体大小 textbox.TextFrame.TextRange.Font.Color.RGB = Color.DarkViolet.ToArgb(); //设置文本颜色 }
public pptfile(string pathway) { newapp = new Powerpoint.Application(); newpres = newapp.Presentations.Add(MsoTriState.msoTrue); newslides = newpres.Slides; directorypathway = pathway; newcustomlayout = newpres.SlideMaster.CustomLayouts[7]; createslides(); }
private void OnDisplayShown() { _slides = null; _pptApplication = null; // Go to the first slide and then flick through the presentation const int timeout = 20; var numTimesRetried = 0; while (_slides == null) { if (numTimesRetried++ > timeout) { return; } try { // Get Running PowerPoint Application object _pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPT.Application; } catch (Exception ex) { Log.TraceErr("PowerPointDisplayViewModel.OnDisplayShown: Couldn't find PowerPoint. {0}", ex.Message); _pptApplication = null; } if (_pptApplication == null) { Log.TraceErr("PowerPointDisplayViewModel.OnDisplayShown: Waiting for PowerPoint to load..."); System.Threading.Thread.Sleep(2000); } else { break; } } if (_pptApplication == null) { Log.TraceErr("PowerPointDisplayViewModel.OnDisplayShown: Unable to obtain a running instance of PowerPoint, giving up"); return; } // Get Presentation Object var presentation = _pptApplication.ActivePresentation; // Get Slide collection object _slides = presentation.Slides; // Go to the first slide SetSlide(1); _slideshowController.RunWorkerAsync(); }
internal static void RemoveObjects(Boolean warn) { DialogResult result; if (warn) { string messageBoxText = "Are you sure to remove all the objects in purple?"; string caption = "Warning"; MessageBoxButtons button = MessageBoxButtons.OKCancel; MessageBoxIcon icon = MessageBoxIcon.Warning; result = MessageBox.Show(messageBoxText, caption, button, icon); } else { result = DialogResult.OK; } switch (result) { case DialogResult.OK: PowerPoint.Slides slides = Globals.ThisAddIn.Application.ActivePresentation.Slides; while (CheckObjectsExist()) { foreach (PowerPoint.Slide slide in slides) { //Debug.WriteLine("SlideIndex: " + slide.SlideIndex); PowerPoint.Slide currSlide = slides[slide.SlideIndex]; foreach (PowerPoint.Shape shape in currSlide.Shapes) { //Debug.WriteLine("ShapeID: " + shape.Id); if (shape.Type.Equals(Office.MsoShapeType.msoTextBox)) { //Debug.WriteLine("TextBox Color: " + shape.TextFrame.TextRange.Font.Color.RGB); if (shape.TextFrame.TextRange.Font.Color.RGB.Equals(9109675)) { shape.Delete(); } } else if (shape.Type.Equals(Office.MsoShapeType.msoInkComment)) { //Debug.WriteLine("Ink RGB: " + shape.Line.ForeColor.RGB); if (shape.Line.ForeColor.RGB.Equals(9109675)) { shape.Delete(); } } } } } break; case DialogResult.Cancel: break; } }
private static void RemoveSlides(PowerPoint.Slides slides, COMObjectsHelper comHelper, bool forceRemoveAll = false) { for (int i = slides.Count; i > 0; --i) { var slide = comHelper.Register(() => slides[i]); if (forceRemoveAll || IsSlideEmpty(slide, comHelper)) { slide.Delete(); } } }
private void button2_Click(object sender, EventArgs e) { PowerPoint.Slides slides = app.ActivePresentation.Slides; int count = slides.Count; comboBox1.Items.Clear(); comboBox1.Text = "1"; for (int i = 2; i <= count; i++) { comboBox1.Items.Add(i); } }
public List <IFileItem> AppendShapes(List <PPT.Shape> srcShapes) { PPT.Application ppt = null; PPT.Presentations pres = null; PPT.Presentation pptPresentation = null; try { ppt = new PPT.Application(); pres = ppt.Presentations; pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue); PPT.DocumentWindow wnd = pptPresentation.Windows[1]; //wnd.Height = 200; //wnd.Top = -200; wnd.WindowState = PPT.PpWindowState.ppWindowMinimized; wnd = null; PPT.Slides gSlides = pptPresentation.Slides; int startIndex = gSlides.Count + 1; int count = 0; foreach (PPT.Shape shape in srcShapes) { PPT.Slide slide = gSlides.Add(startIndex + count++, PPT.PpSlideLayout.ppLayoutBlank); shape.Copy(); slide.Shapes.Paste(); slide.Tags.Add(ShapeTag.Tag, ShapeTag.Value); slide.ReleaseCOM(); slide = null; } List <IFileItem> newItems = new List <IFileItem>(); newItems = fileIndex.UpdateIndex(pptPresentation, startIndex); return(newItems); } finally { if (pptPresentation != null) { pptPresentation.Save(); pptPresentation.Close(); } pptPresentation.ReleaseCOM(); pptPresentation = null; pres.ReleaseCOM(); pres = null; ppt.ReleaseCOM(); ppt = null; } }
private void note1_Load(object sender, EventArgs e) { PowerPoint.Slides slides = app.ActivePresentation.Slides; int count = slides.Count; comboBox1.Text = "1"; for (int i = 2; i <= count; i++) { comboBox1.Items.Add(i); } textBox1.Text = Properties.Settings.Default.notesplit; }
public void CreateNewPPT() { application = new PowerPoint.Application(); pptPresentationSet = application.Presentations; pptPresentation = pptPresentationSet.Open(_fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); //customLayout = pptPresentationSet.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText]; pptSlides = pptPresentation.Slides; pptSlide = pptSlides.AddSlide(1, customLayout); textRng = pptSlide.Shapes[1].TextFrame.TextRange; textRng.Font.Name = textDefaultFontName; textRng.Font.Size = textDefaultFontSize; }
public static void SetLanguage(PowerPoint.Slides slides, Office.MsoLanguageID language) { foreach (PowerPoint.Slide slide in slides) { foreach (PowerPoint.Shape shape in slide.Shapes) { // go to helper method to set the language of the shape setLanguageOfShape(shape, language); } } // Also set the default language of the presentation Globals.ThisAddIn.Application.ActivePresentation.DefaultLanguageID = language; }
private void cxFlatButton1_Click(object sender, EventArgs e) { //Microsoft.Office.Interop.PowerPoint.Presentation MyPres = null;//ppt实例 Microsoft.Office.Interop.PowerPoint.Slides AllSlides = null; //PPT中所有的幻灯片 Microsoft.Office.Interop.PowerPoint.Slide MySlide = null; //当前幻灯片 //Microsoft.Office.Interop.PowerPoint.Slide NewSlide = null;//新插入的幻灯片 AllSlides = Globals.ThisAddIn.Application.ActivePresentation.Slides; //获取当前PPT中的所有幻灯片 MySlide = Globals.ThisAddIn.Application.ActiveWindow.View.Slide; //获取选中幻灯片 Microsoft.Office.Interop.PowerPoint.TextRange FQTextRng = null; Microsoft.Office.Interop.PowerPoint.TextRange score = null; Microsoft.Office.Interop.PowerPoint.TextRange limitime = null; Microsoft.Office.Interop.PowerPoint.TextRange answer = null; FQTextRng = MySlide.Shapes["questionDescribe"].TextFrame.TextRange; score = MySlide.Shapes["questionScore"].TextFrame.TextRange; limitime = MySlide.Shapes["questionLimitTime"].TextFrame.TextRange; answer = MySlide.Shapes["questionAnswer"].TextFrame.TextRange; FQTextRng.Font.NameFarEast = "微软雅黑"; //文本框中,中文的字体 FQTextRng.Font.NameAscii = "Calibri"; //文本框中,英文和数字的字体 FQTextRng.Text = JudegeQuestText.Text; //cxFlatTextArea1.Text;//显示的内容 score.Text = scoreBox2.Text; limitime.Text = limitBox1.Text; MySlide.Shapes["questionScore"].TextFrame.TextRange.Text = scoreBox2.Text; MySlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text = limitBox1.Text; if (cxFlatCheckBox1.Checked == true) { answer.Text = "True;"; MySlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "True;"; } else { answer.Text = "False;"; MySlide.Shapes["questionAnswer"].TextFrame.TextRange.Text = "False;"; } System.Diagnostics.Debug.WriteLine(MySlide.Shapes["questionScore"].TextFrame.TextRange.Text + "xixixix"); System.Diagnostics.Debug.WriteLine(MySlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text + "xixixix"); FQTextRng.Font.Bold = MsoTriState.msoFalse; //是否加粗 FQTextRng.Font.Color.RGB = 1 + 1 * 256 + 1 * 256 * 256; //字体颜色,其中ABC直接用自定义颜色中的数字代替即可。 FQTextRng.Font.Size = 24; //字体大小是24. FQTextRng.ParagraphFormat.Alignment = Microsoft.Office.Interop.PowerPoint.PpParagraphAlignment.ppAlignLeft; //文本对齐方式(水平方向) MySlide.Shapes[2].TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorMiddle; //文本对齐方式(垂直方向) }
/// <summary> /// Check whether PowerPoint is running /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckPowerPoint() { try { // Get Running PowerPoint Application object pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPt.Application; } catch (Exception ex) { pptApplication = new PPt.Application(); pptApplication.Visible = MsoTriState.msoTrue; } if (pptApplication != null) { // 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]; if (slide == null) { UnityEngine.Debug.Log("Null"); } } catch { // Get selected slide object in reading view slide = pptApplication.SlideShowWindows[1].View.Slide; if (slide == null) { UnityEngine.Debug.Log("Null"); } } } else { UnityEngine.Debug.Log("Not Found"); } }
private static void RemoveShapesWithEmptyTextFrame(PowerPoint.Slides slides, COMObjectsHelper comHelper) { foreach (PowerPoint.Slide slide in slides) { comHelper.Register(() => slide); var shapes = comHelper.Register(() => slide.Shapes); for (int i = shapes.Count; i > 0; --i) { var shape = comHelper.Register(() => shapes[i]); if (shape.HasTextFrame == MsoTriState.msoTrue && comHelper.Register(() => shape.TextFrame2).HasText == MsoTriState.msoFalse) { shape.Delete(); } } } }
private void button1_Click(object sender, EventArgs e) { PowerPoint.Selection sel = app.ActiveWindow.Selection; if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes) { MessageBox.Show("请选中要导入到备注里的文本框,不同页的文字请先用分隔符分开"); } else { PowerPoint.Slides slides = app.ActivePresentation.Slides; PowerPoint.Shape shape = sel.ShapeRange[1]; if (shape.HasTextFrame == Office.MsoTriState.msoTrue && shape.TextEffect.Text != "") { string sp = textBox1.Text.Trim(); int n = int.Parse(comboBox1.Text.Trim()); string txt = shape.TextEffect.Text; if (txt.Contains(sp)) { int ts = Regex.Matches(txt, sp).Count; if (ts <= slides.Count - n) { String[] arr = txt.Split(char.Parse(sp)).ToArray(); int tcount = arr.Count(); for (int i = 1; i <= tcount; i++) { slides[n + i - 1].NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text = arr[i - 1].Trim(); } MessageBox.Show("备注导入成功"); } else { MessageBox.Show("分隔符数 > 幻灯片页数"); } } else { MessageBox.Show("找不到指定的分隔符"); } } else { MessageBox.Show("所选文本框中无文字"); } } }
private static PowerPoint.Shape FindEmptyShape(PowerPoint.Slides slides, COMObjectsHelper comHelper) { foreach (PowerPoint.Slide slide in slides) { comHelper.Register(() => slide); foreach (PowerPoint.Shape shape in slide.Shapes) { comHelper.Register(() => shape); if (shape.HasTextFrame == MsoTriState.msoTrue && comHelper.Register(() => shape.TextFrame).HasText == MsoTriState.msoFalse) { return(shape); } } } return(null); }
void ppt_start() { try { // Get Running PowerPoint Application object pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPt.Application; // Get PowerPoint application successfully, then set control button enable this.btnFirst.Enabled = true; this.btnNext.Enabled = true; this.btnPrev.Enabled = true; this.btnLast.Enabled = true; //마우스 커스 변경 SetSystemCursor(LoadCursorFromFile("C:\\Users\\Administrator\\Desktop\\AFA_1.1_Server\\PPT_TEST\\laser.cur"), 32512); keybd_event((byte)Keys.F5, 0x45, 0, 0); keybd_event((byte)Keys.F5, 0x45, 0x02, 0); } catch { MessageBox.Show("Please Run PowerPoint Firstly", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } if (pptApplication != null) { // 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; } } }
/// <summary> /// Constructor that creates the PowerPoint object, so that we can add slides to it /// </summary> public Powerpoint() { String strTemplate; strTemplate = Constant.ePath + "eFlash.pot"; //strTemplate = "C:\\Program Files\\eFlash\\Data\\Media\\" + "blank.pot"; //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; //Prevent Office Assistant from displaying alert messages: bAssistantOn = objApp.Assistant.On; objApp.Assistant.On = false; //start sCount at 1 sCount = 1; oCount = 1; }
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; }
protected void Page_Load(object sender, EventArgs e) { try { // Get Running PowerPoint Application object pptApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPoint.Application") as PPt.Application; } catch { } if (pptApplication != null) { // 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; } } }
public void Init() { try { // Get Running PowerPoint Application object pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PPt.Application; pptApplication.SlideShowBegin += pptApplication_SlideShowBegin; pptApplication.SlideShowEnd += pptApplication_SlideShowEnd; if (pptApplication != null) { try { // Get Presentation Object presentation = pptApplication.ActivePresentation; if(PlayPresentation) presentation.SlideShowSettings.Run(); } catch { // Get presentation in protected mode presentation = pptApplication.ActiveProtectedViewWindow.Presentation; if (PlayPresentation) presentation.SlideShowSettings.Run(); } //// 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; } } } catch { //TODO } }
//------------------------------------------------------------------------------- protected void InitializePPT() { application = (PowerPoint.ApplicationClass)Server.CreateObject("PowerPoint.Application"); presentations = application.Presentations; presentation = presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue); slides = presentation.Slides; }
public static void ShowPresentation(string path) { String strTemplate ; //, strPic; string Base = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; string LocalDir = System.IO.Path.GetDirectoryName(Base).Replace("file:\\", ""); strTemplate = System.IO.Path.Combine(LocalDir, "Resources", "Template.pptx"); //"\\\\flrblr001\\windows_data\\From-SLI-Fileserver\\E\\Product Engineering\\Sundar\\svn\\trunk\\CommonBase\\DeviceSpecific\\Si53300\\sample_data\\Template.pptx"; //strPic = "C:\\Windows\\Blue Lace 16.bmp"; //bool bAssistantOn; if (!System.IO.File.Exists(strTemplate)) { System.Windows.MessageBox.Show("Template file is missing, create the file: " + strTemplate); } //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; objApp.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMinimized; }
private void MediaStrip_OnImageClicked(object sender, EventArgs e) { //MessageBox.Show("ImageBox " + (string)sender + " Clicked"); //PPTMediaApplication.PPTApplication. slideIndex = System.Int32.Parse(sender.ToString()); slides = ActiveMediaItem.PPTPresentation.Slides; try { ActiveMediaItem.PPTPresentation.SlideShowWindow.View.GotoSlide(slides.FindBySlideID(slideIndex).SlideNumber); } catch (Exception ex) { MessageBox msgbox; } }
public void ShowSlides() { // Get Slide collection object slides = ActiveMediaItem.PPTPresentation.Slides; // Get Slide count slidescount = slides.Count; // Get current selected slide try { IntPtr screenClassWnd = (IntPtr)0; IntPtr x = (IntPtr)0; if (panel1.Controls.Count > 0) { try { ActiveMediaItem.PPTPresentation.Close(); } catch { } } else { panel1.Controls.Add(PPTMediaApplication.PPTApplication as Control); } ActiveMediaItem.PPTPresentation.SlideShowSettings.StartingSlide = 1; ActiveMediaItem.PPTPresentation.SlideShowSettings.EndingSlide = slides.Count; //panel1.Dock = DockStyle.Bottom; PPTMediaApplication.PPTApplication.Height = panel1.Height; ActiveMediaItem.PPTPresentation.SlideShowSettings.ShowType = PPt.PpSlideShowType.ppShowTypeWindow2; ActiveMediaItem.PPTPresentation.SlideShowSettings.Application.Width = panel1.Height; ActiveMediaItem.PPTPresentation.SlideShowSettings.Application.Height = panel1.Width; ActiveMediaItem.PPTPresentation.SlideShowSettings.ShowScrollbar = MsoTriState.msoFalse; PPt.SlideShowWindow sw = ActiveMediaItem.PPTPresentation.SlideShowSettings.Run(); try { PPTMediaApplication.PPTApplication.Visible = MsoTriState.msoFalse; PPTMediaApplication.PPTApplication.Visible = MsoTriState.msoFalse; } catch { } IntPtr pptptr = (IntPtr)sw.HWND; SetParent(pptptr, panel1.Handle); } catch { // // Get selected slide object in reading view // slide = pptApplication.SlideShowWindows[1].View.Slide; } }
//Create a new and initialize it;s presentation public void Init() { objApp = new PowerPoint.Application(); flag = 0; objPresSet = objApp.Presentations; //objPres = objPresSet.Add(MsoTriState.msoTrue); objPres= objPresSet.Open("c://sample.pptx"); objSlides = objPres.Slides; }