国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP.NET教程 - Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

2020-04-09 16:52 ASP.NET教程

本文主要介紹了Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件的具體實例。文章篇尾附上源碼下載,有興趣的朋友可以看下

1.功能說明

輸入文件路徑,在瀏覽器輸出文件預覽信息,經測試360極速(Chrome)、IE9/10、Firefox通過

2.分類文件及代碼說明

DemoFiles 存放可測試文件

Default.aspx  啟動頁

ExcelPreview.cs  Excel預覽類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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預覽類

?
1
2
3
4
5
6
7
8
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  文本文件預覽類

?
1
2
3
4
5
6
7
8
9
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預覽類

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

  Microsoft Word 15.0
  Microsoft Excel 15.0

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

  預覽效果

1、Word

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

2、Excel 

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

3、Pdf

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

4、Txt

Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)

未解決的問題

Pdf、txt文件只能在當前頁顯示,并導致后退鍵無效,請各位幫忙解決此兩種文件和doc、xls一樣在新的tab中打開

5.源碼下載

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!

原文鏈接:http://www.cnblogs.com/gossip/p/3473024.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品久久久久白丝呻吟 | 日韩在线一区二区 | 日韩欧美在线不卡 | 一级黄片毛片免费看 | 欧美天天 | 日本一区二区高清不卡 | 日本午夜视频 | 午夜av电影 | 色天天综合久久久久综合片 | 久久一二 | 91精品在线播放 | 亚洲在线一区二区三区 | 亚洲性网| 黑人中文字幕一区二区三区 | a国产精品| 国产麻豆乱码精品一区二区三区 | 国产美女精品 | 色网在线观看 | 精品国产一区二区三区性色av | 国产毛片毛片 | 国产精品一区电影 | 国产成人一区二区三区 | 国产一二在线 | 俺来也俺也啪www色 性色视频在线 | 91在线免费看 | 国产精品久久99 | 91国内在线观看 | 九九综合 | av免费观看网站 | 三级视频在线 | 九九精品视频在线 | 久久久成人精品 | 国产a视频| 欧美成人a∨高清免费观看 亚洲国产精品尤物yw在线观看 | 懂色av中文字幕一区二区三区 | 久久久99精品免费观看 | 国产成人一区 | 亚洲精品久久一区二区三区 | 国产成人精品一区二区三区视频 | www亚洲成人 | 国产精品高潮呻吟久久 |