目前公司的机制是使用控件在线打开。这个思路是将 ppt 另存为 html 格式,在线打开阅读。
不用安装控件,但是服务器上必须安装 office。
PPTtoHTML
public static void PPTToHtml(string path, string savePath, string wordFileName) {
Microsoft.Office.Interop.PowerPoint.Application ppApp = new
Microsoft.Office.Interop.PowerPoint.Application();
string strSourceFile = path;
string strDestinationFile = savePath+wordFileName+".html";
Microsoft.Office.Interop.PowerPoint.Presentation prsPres =
ppApp.Presentations.Open(strSourceFile, MsoTriState.msoTrue, MsoTriState.msoFalse,
MsoTriState.msoFalse);
prsPres.SaveAs(strDestinationFile,
Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,
MsoTriState.msoTrue);
prsPres.Close();
ppApp.Quit();
}
另外附上 word 和 excel 的转换代码
public static string WordToHtml(string path, string savePath, string wordFileName) {
//在此处放置用户代码以初始化页面
Microsoft.Office.Interop.Word.Application word = new Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { path, true, true });
//转换格式,另存为
Type docType = doc.GetType();
string wordSaveFileName = savePath;
string strSaveFileName = savePath+wordFileName + ".html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null,
doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null,
doc, null);
//退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null,
word, null);
return saveFileName.ToString();
}
评论10