Extract powerpoint titles with C# -
i have powerponint 97-2003 files(.ppt extension) , need extract slide titles programatically using c#. have tried using microsoft.office.interop without success. have search google , maximum have found how obtain reference powerpoint.slide:
using system; using system.collections.generic; using system.linq; using system.text; using microsoft.office.core; using powerpoint = microsoft.office.interop.powerpoint; namespace tester { class program { static void main(string[] args) { microsoft.office.interop.powerpoint.application presentationapp = new microsoft.office.interop.powerpoint.application(); try { string pptpath = @"d:\somefile.ppt"; testreadingtitles(presentationapp, pptpath); } { presentationapp.quit(); } } private static void testreadingtitles(microsoft.office.interop.powerpoint.application presentationapp, string pptpath) { presentationapp.visible = microsoft.office.core.msotristate.msotrue; microsoft.office.interop.powerpoint.presentations presentations = presentationapp.presentations; microsoft.office.core.msotristate readonly = microsoft.office.core.msotristate.msotrue; microsoft.office.core.msotristate untitled = microsoft.office.core.msotristate.msotrue; microsoft.office.core.msotristate withwindow = microsoft.office.core.msotristate.msofalse; microsoft.office.interop.powerpoint.presentation presentation = presentations.open(pptpath, readonly, untitled, withwindow); (int = 0; < presentation.slides.count; i++) { foreach (powerpoint.slide slide in presentation.slides) { string slidetitle = ??????????????????; } } } } }
you can extract titles without looping through shapes.
private static string extractslidetitlefromslide(microsoft.office.interop.powerpoint.slide slide, string defaultvalue) { if (slide.shapes.hastitle == office.msotristate.msotrue) { if (slide.shapes.title.textframe.hastext == office.msotristate.msotrue) { return slide.shapes.title.textframe.textrange.text; } } return defaultvalue; }
Comments
Post a Comment