C#在线预览文档(word,excel,pdf,txt,png)
1、预览方式:将word文件转换成html文件然后预览html文件
2、预览word文件:需要引入Interop.Microsoft.Office.Interop.Word.dll(Com组件)
3、预览Excel文件:需要引入Interop.Microsoft.Office.Interop.Excel.dll(Com组件,Microsoft Excel 12.0(or other version) Object Library)
4、PDF文件直接嵌入到浏览器中进行查看,无需转换(需安装pdf阅读器)
5、文本文件直接嵌入到浏览器进行查看,无需转换
6、图片文件直接嵌入到浏览器进行查看,无需转换
Excel预览方法
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for ExcelPreview
/// </summary>
public class ExcelPreview
{
public static void Priview(System.Web.UI.Page p, string inFilePath, string outDirPath = "")
{
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook xls = null;
excel = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
object trueObject = true;
excel.V