c# - Two PPT Presentation is opening instead of one while running through VISUAL STUDIO 2010 -
i facing problem not able carve out solution. have written program in powerpoint presentation 2 slides developed using c#. when run program working fine blank powerpoint presentation created (presentation2.pptx
). not able understand why blank presentation created. please me through this.
below code:
private void thisaddin_startup(object sender, system.eventargs e) { dataset ds = new dataset(); sqlconnection con = new sqlconnection(@"data source=*****;initial catalog=******;user id=****;password=******"); sqlcommand sqlcomm = new sqlcommand("powerpointtest", con); sqlcomm.commandtype = commandtype.storedprocedure; sqldataadapter da = new sqldataadapter(); da.selectcommand = sqlcomm; da.fill(ds); powerpoint.application pptapplication = new powerpoint.application(); microsoft.office.interop.powerpoint.slides slides; microsoft.office.interop.powerpoint._slide slide; microsoft.office.interop.powerpoint._slide slide1; microsoft.office.interop.powerpoint.textrange objtext; // create presentation file powerpoint.presentation pptpresentation = pptapplication.presentations.add(office.msotristate.msotrue); microsoft.office.interop.powerpoint.customlayout customlayout = pptpresentation.slidemaster.customlayouts[microsoft.office.interop.powerpoint.ppslidelayout.pplayouttext]; // create new slide slides = pptpresentation.slides; slide = slides.addslide(1, customlayout); slide1 = slides.addslide(2, customlayout); slide.applytheme(@"c:\program files\microsoft office\document themes 14\austin.thmx"); slide1.applytheme(@"c:\program files\microsoft office\document themes 14\austin.thmx"); // add title objtext = slide.shapes[1].textframe.textrange; objtext.text = "test"; objtext.font.name = "arial"; objtext.font.size = 32; objtext = slide1.shapes[1].textframe.textrange; objtext.text = "test1"; objtext.font.name = "arial"; objtext.font.size = 40; objtext = slide.shapes[2].textframe.textrange; string username = convert.tostring(ds.tables[0].rows[0]["username"]); string loginid = convert.tostring(ds.tables[0].rows[0]["loginid"]); string emailid1 = convert.tostring(ds.tables[0].rows[0]["emailid1"]); objtext.text = "username:" + username +"\n loginid:"+ loginid +"\n email id:"+emailid1+"."; objtext = slide1.shapes[2].textframe.textrange; objtext.text = "content goes here\nyou cannot add text\nitem 3"; objtext.font.size = 24; slide.notespage.shapes[2].textframe.textrange.text = "test"; pptpresentation.saveas(@"c:\temp\test.pptx", microsoft.office.interop.powerpoint.ppsaveasfiletype.ppsaveasdefault, office.msotristate.msotrue); } private void thisaddin_shutdown(object sender, system.eventargs e) { } #region vsto generated code /// <summary> /// required method designer support - not modify /// contents of method code editor. /// </summary> private void internalstartup() { this.startup += new system.eventhandler(thisaddin_startup); this.shutdown += new system.eventhandler(thisaddin_shutdown); } #endregion }
when create add-in project office applications, thisaddin
class have field called application
1 running application
object office application. should use interact running application rather having line:
powerpoint.application pptapplication = new powerpoint.application();
that is, should delete line , replace uses of pptapplication
application
.
1the field isn't visible in .cs
file should able see in intellisense or expanding solution explorer:
Comments
Post a Comment