亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Asp.net實(shí)現(xiàn)直接在瀏覽器預(yù)覽Word、Excel、PDF、Txt文件(附源碼)

 更新時(shí)間:2016年12月09日 12:20:47   作者:扯  
本文主要介紹了Asp.net實(shí)現(xiàn)直接在瀏覽器預(yù)覽Word、Excel、PDF、Txt文件的具體實(shí)例。文章篇尾附上源碼下載,有興趣的朋友可以看下

1.功能說(shuō)明

輸入文件路徑,在瀏覽器輸出文件預(yù)覽信息,經(jīng)測(cè)試360極速(Chrome)、IE9/10、Firefox通過(guò)

2.分類文件及代碼說(shuō)明

DemoFiles 存放可測(cè)試文件

Default.aspx  啟動(dòng)頁(yè)

ExcelPreview.cs  Excel預(yù)覽類

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.Visible = false;
 excel.DisplayAlerts = false;
 string randomName = DateTime.Now.Ticks.ToString(); //output fileName
 xls = excel.Workbooks.Open(inFilePath, missing, trueObject, missing,
     missing, missing, missing, missing, missing, missing, missing, missing,
     missing, missing, missing);
 //Save Excel to Html
 object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
 Workbook wsCurrent = xls;//(Workbook)wsEnumerator.Current;
 String outputFile = outDirPath + randomName + ".html";
 wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
    missing, XlSaveAsAccessMode.xlNoChange, missing,
    missing, missing, missing, missing);
 excel.Quit();
 //Open generated Html
 Process process = new Process();
 process.StartInfo.UseShellExecute = true;
 process.StartInfo.FileName = outputFile;
 process.Start();
 } 

4.PDfPreview.cs   Pdf預(yù)覽類

public static void Priview(System.Web.UI.Page p, string inFilePath)
 {
 p.Response.ContentType = "Application/pdf";
 string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1);
 p.Response.AddHeader("content-disposition", "filename=" + fileName);
 p.Response.WriteFile(inFilePath);
 p.Response.End();
 }

5.TextFilePreview.cs  文本文件預(yù)覽類

 public static void Preview(System.Web.UI.Page p, string inFilePath)
 {
 string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1);
 p.Response.ContentType = "text/plain";
 p.Response.ContentEncoding = System.Text.Encoding.UTF8; //保持和文件的編碼格式一致
 p.Response.AddHeader("content-disposition", "filename=" + fileName);
 p.Response.WriteFile(inFilePath);
 p.Response.End();
 }

6. WordPreview.cs  Word預(yù)覽類

7.Readme.txt  說(shuō)明了基本功能及引用Com組件的方法(首先需要安裝office),需引入的組件包括

  Microsoft Word 15.0
  Microsoft Excel 15.0

  預(yù)覽效果

1、Word

2、Excel 

3、Pdf

4、Txt

未解決的問(wèn)題

Pdf、txt文件只能在當(dāng)前頁(yè)顯示,并導(dǎo)致后退鍵無(wú)效,請(qǐng)各位幫忙解決此兩種文件和doc、xls一樣在新的tab中打開(kāi)

5.源碼下載http://xiazai.jb51.net/201612/yuanma/FilePreviewInBrowser_jb51.rar

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論