Examples of exporting pptfile data in ASP. NET, asp. netppt
Some time ago, due to work needs, you need to add the export and download of ppt data. I found that there were not many such materials on the network. I found some relevant materials and finally completed the relevant functions through my own experiments. At the request of Boyou, I would like to share my experience with you.
Before doing this, add the 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_12.16.ppt", Server. mapPath (". "), DateTime. now. ticks. toString (); // template path referenced by the ppt 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 (); // if it already exists, delete if (File. exists (string) path) {File. delete (string) path);} Object Nothing = Missing. value; // apply the template MyPres = MyApp. presentations. open (MyTemplateFile, MsoTriState. msoFalse, MsoTriState. msoFalse, MsoTriState. msoFalse); MyPresSet = MyApp. presentations; objSlides = MyPres. slides; // create the first PPT ppLayoutTitle. Specify the template homepage MySlide = objSlides. add (1, PowerPoint. ppSlideLayout. ppLayoutTitle); // Add a line of text (left: 10, top: 110, width: 700, height: 400) objTextRng = MySlide. shapes. addLabel (MsoTextOrientation. (msoTextOrientationHorizontal, 10,110,700,400 ). textFrame. textRange; objTextRng. text = "PPT"; objTextRng. font. color. RGB = 0x66CCFF; // set the color of the word objTextRng. font. size = 42; // font Size // create the second PPT ppLayoutBlank and specify MySlide = objSlides. add (2, PowerPoint. ppSlideLayout. ppLayoutBlank); // Insert the image MySlide. shapes. addPicture ("1.jpg", MsoTriState. msoFalse, MsoTriState. msoTrue, 110,140,500,300); // create the third PPT ppLayoutTitleOnly to specify only the title page MySlide = objSlides. add (3, PowerPoint. ppSlideLayout. ppLayoutTitleOnly); objTextRng = MySlide. shapes [1]. textFrame. textRange; objTextRng. text = "directory"; objTextRng. font. size = 32; // Insert the image MySlide. shapes. addPicture ("1.jpg", MsoTriState. msoFalse, MsoTriState. msoTrue, 110,140,500,300); // create the fourth PPT MySlide = objSlides. add (3, PowerPoint. ppSlideLayout. ppLayoutBlank); // Add a table named 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 the PowerPoint Format. ppSaveAsFileType format = PowerPoint. ppSaveAsFileType. ppSaveAsDefault; // Save the MyPres content. saveAs (path, format, Microsoft. office. core. msoTriState. msoFalse); // close the excelDoc object MyPres. close (); // Close the excelApp Component Object MyApp. quit ();}
Articles you may be interested in:
- C # how to convert PPT to HTML
- C # implementation code for converting word ppt excel files to pdf files
- How to convert a ppt document to a pdf file using asp.net