Some time ago due to the needs of the work, the need to increase the PPT data export download. found that the network on this aspect of information is not a lot of sporadic to find some relevant information, after their own experiments, and finally complete the relevant functions. Chongboyu request, here to share my experience, the bad place also hope that we have a lot to point out.
Before you do, you first need to add the relevant reference Microsoft.Office.Interop.PowerPoint.dll.
Using PowerPoint = Microsoft.Office.Interop.PowerPoint;
The Operation PPT code is as follows:
Copy Code
public void Createppt () {try {//ppt storage path string path = String.
Format ("{0}/{1}.ppt", Server.MapPath ("."), DateTime.Now.Ticks.ToString ());
PPT-Referenced template path string mytemplatefile = "D:\\test.pot";
Powerpoint.applicationclass MyApp;
PowerPoint.Presentations Mypresset;
Powerpoint._presentation Mypres;
PowerPoint.Shape Objshape;
Powerpoint.slides objslides;
Powerpoint._slide MySlide;
Powerpoint.textrange objtextrng;
Powerpoint.table Table = null;
MYAPP = new Powerpoint.applicationclass ();
Delete if (file.exists (string) path) {File.delete ((string) path) if it already exists;
Object nothing = Missing.Value; Format Template mypres = MyApp.Presentations.Open (Mytemplatefile, Msotristate.msofalse, Msotristate.msofalse, MSOTRISTATE.M
Sofalse);
Mypresset = myapp.presentations;
Objslides = Mypres.slides; Create the first sheet of PPT pplayouttitle Specify template Home myslide = Objslides.add (1, PowerPoint.PpSlideLayout.ppLayoutTitle); Add one line of text (left:10,top:110,width:700,height:400) objtextrng = MySlide.Shapes.AddLabel (Msotextorientation.msotextori Entationhorizontal, 10, 110, 700, 400).
TextFrame.TextRange;
Objtextrng.text = "PPT"; ObjTextRng.Font.Color.RGB = 0X66CCFF; Sets the color of the word objTextRng.Font.Size = 42; Font size//create second PPT pplayoutblank Specify untitled page myslide = Objslides.add (2, PowerPoint.PpSlideLayout.ppLayoutB
Lank);
Insert Picture MySlide.Shapes.AddPicture ("1.jpg", Msotristate.msofalse, Msotristate.msotrue, 110, 140, 500, 300); Create a third PPT pplayouttitleonly specify only the title page MySlide = Objslides.add (3, POWERPOINT.PPSLIDELAYOUT.PPLAYOUTTITLEONL
y); OBJTEXTRNG = myslide.shapes[1].
TextFrame.TextRange;
Objtextrng.text = "Directory";
ObjTextRng.Font.Size = 32; Insert Picture MySlide.Shapes.AddPicture ("1.jpg", Msotristate.msofalse, Msotristate.msotrue, 110, 140, 500, 300);
Create fourth ppt myslide = Objslides.add (3, PowerPoint.PpSlideLayout.ppLayoutBlank);
Add a table Objshape = MySlide.Shapes.AddTable (3, 3, 105, 150, 400, 100);
Table = objshape.table; for (int i = 1; I <= table. Rows.Count; i++) {for (int j = 1; J <= table). Columns.count; J + +) {table. Cell (i, J).
Shape.TextFrame.TextRange.Font.Size = 12; Table. Cell (i, J). Shape.TextFrame.TextRange.Text = string.
Format ("[{0},{1}]", I, j); }//Save format Powerpoint.ppsaveasfiletype formats = PowerPoint.PpSaveAsFileType.ppSa
Veasdefault;
Content save Mypres.saveas (path, format, Microsoft.Office.Core.MsoTriState.msoFalse);
Closes the Exceldoc Document Object Mypres.close ();
Closes the Excelapp Component Object Myapp.quit ();
}