想用c#实现word、excel、pdf等在线预览,求大神!!!! 如果只是看看,整个服务,把上传的PDF,Word什么的转成图片,Web端直接显示图片就行了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我这主要要实现的是excel预览。所以这条路走不通啊 是啊。貌似发现office web apps能实现。不过那个貌似也是需要付费的。 Google 下 Excel Web Apphttp://office.microsoft.com/zh-cn/web-apps-help/HA010378338.aspx 这个我准备试试,不过资料上面说这个貌似文件服务器只能是微软的live,如果要部署在自己电脑上是需要购买授权的 还是购买付费的产品吧。个人推荐pageoffice 用微软的web office app吧,配置一个windowsserver环境,去网上找找教程咯。不麻烦 /// <summary> /// word 转换为html /// </summary> /// <param name="path">要转换的文档的路径</param> /// <param name="savePath">转换成的html的保存路径</param> /// <param name="wordFileName">转换后html文件的名字</param> private void WordToHtml(string path, string savePath, string wordFileName) { Word.ApplicationClass word = new Word.ApplicationClass(); 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[] {(object)path, true, true }); Type docType = doc.GetType(); 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); wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); } /// <summary> /// excel 转换为html /// </summary> /// <param name="path">要转换的文档的路径</param> /// <param name="savePath">转换成的html的保存路径</param> /// <param name="wordFileName">转换后html文件的名字</param> public static void ExcelToHtml(string path, string savePath, string wordFileName) { string str = string.Empty; Microsoft.Office.Interop.Excel.Application repExcel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = null; Microsoft.Office.Interop.Excel.Worksheet worksheet = null; workbook = repExcel.Application.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]; object htmlFile = savePath + wordFileName + ".html"; object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml; workbook.SaveAs(htmlFile, ofmt, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); object osave = false; workbook.Close(osave, Type.Missing, Type.Missing); repExcel.Quit(); } /// <summary> /// ppt转换为html /// </summary> /// <param name="path">要转换的文档的路径</param> /// <param name="savePath">转换成的html的保存路径</param> /// <param name="wordFileName">转换后html文件的名字</param> 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, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue); prsPres.Close(); ppApp.Quit(); } 请教vs2008编辑器的一个小问题 devexpress的layoutControlItem控件隐藏后怎么显示出来 虚心求教一个多线程问题 基于Web的TCP聊天室(C#) 关于.NET2003开发软件怎么使用的问题(问题提的太菜了~~) 多窗口问题 2003 .net框架下如何运行asp程序 如何将我自己的通讯录导出到OE等软件兼容的格式,比如说wab格式等 二个时间怎么比较??急!! 如果子窗体用Singleton模式,那么我关掉后怎么再打开 绘制个图形后如何旋转? 数组付值
/// word 转换为html
/// </summary>
/// <param name="path">要转换的文档的路径</param>
/// <param name="savePath">转换成的html的保存路径</param>
/// <param name="wordFileName">转换后html文件的名字</param>
private void WordToHtml(string path, string savePath, string wordFileName)
{
Word.ApplicationClass word = new Word.ApplicationClass();
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[] {(object)path, true, true });
Type docType = doc.GetType();
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);
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
} /// <summary>
/// excel 转换为html
/// </summary>
/// <param name="path">要转换的文档的路径</param>
/// <param name="savePath">转换成的html的保存路径</param>
/// <param name="wordFileName">转换后html文件的名字</param>
public static void ExcelToHtml(string path, string savePath, string wordFileName)
{
string str = string.Empty;
Microsoft.Office.Interop.Excel.Application repExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = null;
Microsoft.Office.Interop.Excel.Worksheet worksheet = null;
workbook = repExcel.Application.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];
object htmlFile = savePath + wordFileName + ".html";
object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
workbook.SaveAs(htmlFile, ofmt, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
object osave = false;
workbook.Close(osave, Type.Missing, Type.Missing);
repExcel.Quit();
} /// <summary>
/// ppt转换为html
/// </summary>
/// <param name="path">要转换的文档的路径</param>
/// <param name="savePath">转换成的html的保存路径</param>
/// <param name="wordFileName">转换后html文件的名字</param>
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, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
prsPres.Close();
ppApp.Quit();
}