C # convert PPT to HTML

Source: Internet
Author: User
I wrote a small program today to convert ppt files into html files. I am afraid I will forget it later. I will record it here and share it with you.
The source code is as follows:

Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. IO;
Using PPT = Microsoft. Office. Interop. PowerPoint;
Using System. Reflection;

Namespace WritePptDemo
{
Class Program
{
Static void Main (string [] args)
{
String path; // file path variable

PPT. Application pptApp; // Excel Application Variables
PPT. Presentation pptDoc; // Excel document variable

PPT. Presentation pptDoctmp;

Path = @ "C: \ MyPPT.ppt"; // path
PptApp = new PPT. ApplicationClass (); // Initialization

// Delete an existing one
If (File. Exists (string) path ))
{
File. Delete (string) path );
}

// Because the COM library is used, many variables need to be replaced by Nothing.
Object Nothing = Missing. Value;
PptDoc = pptApp. Presentations. Add (Microsoft. Office. Core. MsoTriState. msoFalse );
PptDoc. Slides. Add (1, Microsoft. Office. Interop. PowerPoint. PpSlideLayout. ppLayoutText );

String text = "sample text ";

Foreach (PPT. Slide slide in pptDoc. Slides)
{
Foreach (PPT. Shape shape in slide. Shapes)
{
Shape. TextFrame. TextRange. InsertAfter (text );
}
}

// WdSaveFormat is the Save format of the Excel document
PPT. PpSaveAsFileType format = PPT. PpSaveAsFileType. ppSaveAsDefault;

// Save the content of the excelDoc object as an XLSX document
PptDoc. SaveAs (path, format, Microsoft. Office. Core. MsoTriState. msoFalse );

// Close the excelDoc object
PptDoc. Close ();

// Close the excelApp Component Object
PptApp. Quit ();

Console. WriteLine (path + "created! ");

Console. ReadLine ();

String pathHtml = @ "c: \ MyPPT.html ";

PPT. Application pa = new PPT. ApplicationClass ();

PptDoctmp = pa. presentations. open (path, Microsoft. office. core. msoTriState. msoTrue, Microsoft. office. core. msoTriState. msoFalse, Microsoft. office. core. msoTriState. msoFalse );
PPT. PpSaveAsFileType formatTmp = PPT. PpSaveAsFileType. ppSaveAsHTML;
PptDoctmp. SaveAs (pathHtml, formatTmp, Microsoft. Office. Core. MsoTriState. msoFalse );
PptDoctmp. Close ();
Pa. Quit ();
Console. WriteLine (pathHtml + "created! ");
}
}
}

The above program uses C # To first create a ppt file and write text to it, and then convert the ppt to html. What needs to be explained for the above program is
To reference dll, add references to the project and select microsoft powerpoint 11.0 object library from the com component. If your computer does not have office 2003 installed, if office 2007 is installed, microsoft powerpoint 12.0 object library is installed. And even if you reference it successfully, it will still fail to compile because office PIA is rarely installed. During office installation, if you choose a typical installation, this will not be installed, this is only applicable to developers. You can download an office PIA installation on the Internet.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.