//string filePath; public string gettext(string filePath) { string fileData = ""; Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@filePath, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse); for (int i = 0; i < presentation.Slides.Count; i++) { foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (PowerPoint.Shape)item; if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame.HasText == MsoTriState.msoTrue) { var textRange = shape.TextFrame.TextRange; var text = textRange.Text; fileData += text + " "; } } } } PowerPoint_App.Quit(); return(fileData); }
public static IList <string> GetPresentationTitles(string pptPath) { IList <string> result = new List <string>(); var presentationApp = new Microsoft.Office.Interop.PowerPoint.Application(); try { presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations; var readOnly = Microsoft.Office.Core.MsoTriState.msoTrue; var untitled = Microsoft.Office.Core.MsoTriState.msoTrue; var withWindow = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPath, readOnly, untitled, withWindow); int i = 0; foreach (PowerPoint.Slide slide in presentation.Slides) { string defaultTitle = String.Format("Slide {0}", i); String shapeTitle = ExtractSlideTitlefromShape(slide, defaultTitle); result.Add(shapeTitle); } } finally { presentationApp.Quit(); } return(result); }
void oPPT_PresentationOpen(Microsoft.Office.Interop.PowerPoint.Presentation Pres) { if (FileEventCB.Checked) { string text = "Presentation Open: " + Pres.Name; SetText(text); WriteToSocket(text); } }
public static void PPTToHtml(string path) { Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); string strSourceFile = path; string strDestinationFile = path.Substring(0, path.Length - 3) + ".html"; Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue); prsPres.Close(); ppApp.Quit(); }
/// <summary> /// Executes a shell command synchronously. /// </summary> /// <param name="command">string command</param> /// <returns>string, as output of the command.</returns> public static void OpenPowerPoint(string file) { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(file, ofalse, ofalse, otrue); System.Diagnostics.Debug.Print(p.Windows.Count.ToString()); MessageBox.Show(pptApp.ActiveWindow.Caption); }
public void Add2Index() { Microsoft.Office.Interop.PowerPoint.Presentation pp = null; StringBuilder sb = new StringBuilder(); sb.Append(string.Empty); string err = string.Empty; try { pp = PptApp.Presentations.Open(fileMeta.FileName, OfficeCore.MsoTriState.msoTrue, OfficeCore.MsoTriState.msoFalse, OfficeCore.MsoTriState.msoFalse); foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pp.Slides) { foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes) { if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { var textFrame = shape.TextFrame; if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { var textRange = textFrame.TextRange; string item = Convert.ToString(textRange.Text); sb.Append(item); sb.Append(Environment.NewLine); } } } } } catch (Exception ex) { lock (oLockSbErr) { sbErr.Append(ex.Message); sbErr.Append(" "); sbErr.Append(fileMeta.FileName); sbErr.Append(Environment.NewLine); } } finally { if (pp != null) { pp.Close(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pp); pp = null; } } luceneIndex.BuildIndex(sb.ToString(), fileMeta.FileName, fileMeta.LastWriteTime); }
public string[] GetText(string sFileName) { StringBuilder sb = new StringBuilder(); string err = string.Empty; try { if (pptApp == null) { pptApp = new PowerPoint.Application(); } pp = pptApp.Presentations.Open(sFileName, OfficeCore.MsoTriState.msoTrue, OfficeCore.MsoTriState.msoFalse, OfficeCore.MsoTriState.msoFalse); foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pp.Slides) { foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes) { if (shape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { var textFrame = shape.TextFrame; if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { var textRange = textFrame.TextRange; string item = Convert.ToString(textRange.Text); sb.Append(item); sb.Append(Environment.NewLine); } } } } } catch (Exception ex) { sb.Append(sFileName); err = sFileName + " - " + ex.Message; } finally { if (pp != null) { pp.Close(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pp); pp = null; } } return(new string[] { sb.ToString(), err }); }
public PowerPointDocumentParser(string inputFilePath, EquationToLaTeXConverter form) { this.form = form; char[] separator = { '\\' }; string[] directories = inputFilePath.Split(separator, StringSplitOptions.RemoveEmptyEntries); string dir = ""; for (int i = 0; i < directories.Length - 1; i++) { dir += directories[i] + '\\'; } this.inputFileDir = dir; this.inputFileName = directories[directories.Length - 1]; Console.WriteLine(inputFileName); this.app = new PowerPoint.Application(); object isVisible = true; File.SetAttributes(inputFilePath, FileAttributes.Normal); if (form.checkBox1.Checked == false) { pptOpen = this.app.Presentations.Open(inputFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, WithWindow: MsoTriState.msoFalse); } if (form.checkBox1.Checked == true) { pptOpen = this.app.Presentations.Open(inputFilePath, MsoTriState.msoTrue, MsoTriState.msoTrue, WithWindow: MsoTriState.msoTrue); } //pptOpen.Activate(); this.slides = pptOpen.Slides; }
public static void convert(string originalFile, string outPutFile) { // Word Converter var powerPointApp = new PowerPoint.Application(); //powerPointApp.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Interop.PowerPoint.Presentation presentation = null; Microsoft.Office.Interop.PowerPoint.Presentations presentations = null; presentations = powerPointApp.Presentations; presentation = presentations.Open(originalFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse); presentation.ExportAsFixedFormat(outPutFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, Microsoft.Office.Core.MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, false, true, true, true, false, Type.Missing); powerPointApp.Quit(); return; }
private static string SaveAsPptx(string pptPathIn) { Microsoft.Office.Interop.PowerPoint.Application presentationApp = new Microsoft.Office.Interop.PowerPoint.Application(); string pptxPathOut = null; try { string pptDir = Path.GetDirectoryName(pptPathIn); string pptFileNameOnly = Path.GetFileNameWithoutExtension(pptPathIn); pptxPathOut = Path.Combine(pptDir, pptFileNameOnly + ".pptx"); presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations; Microsoft.Office.Core.MsoTriState readOnly = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState untitled = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState withWindow = Microsoft.Office.Core.MsoTriState.msoFalse; Debug.Print("Opening ppt file {0} ...", pptPathIn); Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPathIn, readOnly, untitled, withWindow); Debug.Print("Starting creation of pptx from ppt {0}", pptPathIn); presentation.SaveCopyAs(pptxPathOut, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, Microsoft.Office.Core.MsoTriState.msoFalse); Debug.Print("Successfully created pptx {0} from ppt {1}", pptxPathOut, pptPathIn); } catch (Exception e) { Debug.Print("Error during creating pptx from ppt " + pptPathIn, e); } finally { presentationApp.Quit(); } return(pptxPathOut); }
void ThisAddIn_NewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation Pres) { }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine(@"Usage: ppt2img <ppt|pptx> [options] Option: -t|--type <png|jpg> -o|--output <dir>"); return; } try { for (int i = 0; i < args.Length; ++i) { if (args[i] == "--type" || args[i] == "-t") { ++i; imgType = args[i]; } else if (args[i] == "--output" || args[i] == "-o") { ++i; outDir = args[i]; } else if (inPpt.Length == 0) { inPpt = args[i]; } else { throw new Exception("Unknow option '" + args[i] + "'"); } } } catch (Exception e) { Console.WriteLine("Invalid args"); Console.WriteLine("{0}", e.Message); return; } outDir = Path.GetFullPath(outDir); inPpt = Path.GetFullPath(inPpt); baseName = Path.GetFileNameWithoutExtension(inPpt); Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(inPpt, MsoTriState.msoTrue /* ReadOnly=true */, MsoTriState.msoTrue /* Untitled=true */, MsoTriState.msoFalse /* WithWindow=false */); int count = presentation.Slides.Count; for (int i = 0; i < count; i++) { Console.WriteLine("Saving slide {0} of {1}...", i + 1, count); String outName = String.Format(@"{0}\{1}_slide{2}.{3}", outDir, baseName, i, imgType); try { presentation.Slides[i + 1].Export(outName, imgType, width, height); } catch (Exception e) { Console.WriteLine("Failed to export slide {0}", i + 1); Console.WriteLine("{0}", e.Message); break; } } Console.WriteLine("Done"); }
/* * http://mantascode.com/c-get-text-content-from-microsoft-powerpoint-file/ */ // under construction - still buggy on: shape.Chart to string public void readPPTText(string pptfile) { Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(pptfile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); /* MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse * required to not open the file in a separate process. */ string presentation_text = ""; string fulltext = ""; for (int i = 0; i < presentation.Slides.Count; i++) { //fulltext += "\n\n"; //fulltext += "Slide:" + (i + 1) + " || "; Console.WriteLine("______Slide # " + (i + 1) + "________"); foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; /* if shape object is a group of shapes * http://www.pptfaq.com/FAQ00600_Changing_shapes_within_groups_-without_ungrouping-.htm */ if (shape.Type == MsoShapeType.msoGroup) { Console.WriteLine(shape.GroupItems.Count); for (int j = 1; j <= shape.GroupItems.Count; ++j) { string temp = getShapeText((Microsoft.Office.Interop.PowerPoint.Shape)shape.GroupItems[j]); fulltext += temp; presentation_text += temp; } } /* else if shape object is NOT group of shapes and just a Shape*/ else { string temp = getShapeText(shape); fulltext += temp; presentation_text += temp; } } presentation_text = presentation_text.Replace("\"", " ").Replace("\'", " ").Replace("\n", " ").Replace("\r", " "); //presentation_text= presentation_text.Replace("\'", " "); //Console.WriteLine("insert into weekly (filename, hashtext, imgthumb, imglarge) values ('" + pptfile + "', '" + presentation_text + "', '/img/weekly/" + pptfile + "thumb_slide" + (i + 1) + ".png', '/img/weekly/" + pptfile + "slide" + (i + 1) + ".png') "); //db.Insert("insert into weekly (filename, hashtext, imgthumb, imglarge) values ('" + pptfile + "', '" + presentation_text + "', '/img/weekly/" + pptfile + "_slide" + (i + 1) + ".png', '/img/weekly/" + pptfile + "_slide" + (i + 1) + ".png') "); Console.Write("Slide:" + (i + 1) + ":\n" + presentation_text); Console.Write("\n "); Console.ReadKey(); presentation_text = ""; } //System.IO.File.WriteAllText("G:\\text.txt",fulltext); System.IO.File.WriteAllText("text.txt", fulltext); PowerPoint_App.Quit(); Console.WriteLine(presentation_text); Console.ReadLine(); }
// スライドショーの終了 void Application_SlideShowEnd(Microsoft.Office.Interop.PowerPoint.Presentation Pres) { SlideShow = null; }