标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using PPT = Microsoft.Office.Interop.PowerPoint;
using System.Reflection;
//要调用到反射相关内容,就要引入这个。从已经编译好的程序集里面创建出一个实例,然后调用(应用)这个实例
namespace html_ppt
{
public partial class ppt_html : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Command(object sender, CommandEventArgs e)
{
string path; //文件路径变量
PPT.Application pptApp; //Excel应用程序变量
PPT.Presentation pptDoc; //Excel文档变量
PPT.Presentation pptDoctmp;
path = @"E:\MyPPT.ppt"; //路径
pptApp = new PPT.ApplicationClass(); //初始化
//如果已存在,则删除
if (File.Exists((string)path))
{
File.Delete((string)path);
}
//由于使用的是COM库,因此有许多变量需要用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 = "示例文本";
foreach (PPT.Slide slide in pptDoc.Slides)
{
foreach (PPT.Shape shape in slide.Shapes)
{
shape.TextFrame.TextRange.InsertAfter(text);
}
}
//WdSaveFormat为Excel文档的保存格式
PPT.PpSaveAsFileType format = PPT.PpSaveAsFileType.ppSaveAsDefault;
//将excelDoc文档对象的内容保存为XLSX文档
pptDoc.SaveAs(path, format, Microsoft.Office.Core.MsoTriState.msoFalse);
//关闭excelDoc文档对象
pptDoc.Close();
//关闭excelApp组件对象
pptApp.Quit();
//Console.WriteLine(path + " 创建完毕!");
//Console.ReadLine();
string pathHtml = @"E:\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 + " 创建完毕!");
}
}
}
microsoft office 14.0 object library
Microsoft.Office.Interop.PowerPoint
欢迎提意见
ppt转换为html格式 抄的别人的 但是改成了web版 比较简陋
标签:
原文地址:http://www.cnblogs.com/cxl123/p/5416472.html