//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); }
static void Main(string[] args) { string fileName = @"C:\Presentation1.pptx"; string exportName = "video_of_presentation"; string exportPath = @"C:\{0}.wmv"; 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(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); try { oPres.CreateVideo(exportName); oPres.SaveCopyAs(String.Format(exportPath, exportName), PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue); } finally { ppApp.Quit(); } }
private void button5_Click(object sender, EventArgs e) { string fileName = @"D:\Univer\Anul-III\Sem-II\SM\Lab4\SM_Lab_4\curs2.ppt"; string exportName = "video_of_presentation"; string exportPath = @"D:\Univer\Anul-III\Sem-II\SM\Lab4\SM_Lab_4\{0}.mp4"; 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(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); try { oPres.CreateVideo(exportName); oPres.SaveCopyAs(String.Format(exportPath, exportName), PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue); } finally { 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 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); }
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(); }