zoukankan      html  css  js  c++  java
  • 如何在浏览器网页中显示word文件内容

    如何在浏览器网页中显示word文件内容  

     

    把word文件读到byte[]中,再Response.OutputStream.Write(bytes)到客户端去 

    Page_Load事件中写:        

      //FileStream   fs   =   new   FileStream("c:\1.doc",   FileMode.Open,   FileAccess.Read);  FileStream fs = new FileStream(Server.MapPath("files\1.doc"),FileMode.Open,   FileAccess.Read);      

      byte[]   bytes   =   new   byte[(int)fs.Length];  

      fs.Read(bytes,   0,   bytes.Length);  

      fs.Close();  

      Response.ContentType   =   "application/msword";  

      //Response.OutputStream(bytes);   

    Response.OutputStream.Write(bytes,0, bytes.Length);

      Response.End();

    在网页中显示.txt文件的内容:

    直接就可以显示,如果想放到表格中,可以<iframe   src="XXX.txt"></iframe>

    word文件也可以照此。

    为了正确处理word等格式,你需要在HTML文件中设置好该文件类型,比如:

    <meta http-equiv="Content-Type" content="Application/msword">

    还有其它经常设置的文件类型:

    Application/msword Microsoft Word Document

    application/pdf PDF Document

    application/wordperfect6.0 WordPerfect 6.0 Document

    application/zip ZIP archive

    audio/x-wav WAV audio format

    audio/midi MIDI audio format

    audio/x-pn-realaudio RealAudio

    image/gif GIF image format

    image/jpeg JPEG image format

    image/png PNG image format

    text/html HTML document

    text/plain Plain text

    video/mpeg MPEG video format

    video/quicktime QuickTime video format

    video/x-msvideo AVI video format

    文章来源于易贤网http://www.ynpxrz.com/n765461c2023.aspx

    还有一种,做参考

    response.setContentType("application/vnd.ms-excel"); 
    File file =new File("D:/test.xls"); 
    FileInputStream in=new FileInputStream(file); 
    byte[] buffer=new byte[in.available()]; 
    in.read(buffer); 
    response.getOutputStream().write(buffer); 
    response.getOutputStream().flush();

  • 相关阅读:
    Spring相关知识点
    动态代理jdk和cglib的区别
    keepalived+nginx+tomcat+redis集群环境部署
    MongoDB_4.4 安装和配置
    vsCode 账号间同步 配置,插件
    vue 全局导航 router.beforeEach()
    网页左右两边元素高度自适应,两个元素高度一致,一面高度跟随另一面的高度变化而变化
    git 中 ssh key 的生成
    vscode html 自定义模板
    vscode vue 定义 单文件模板
  • 原文地址:https://www.cnblogs.com/vic_lu/p/4290624.html
Copyright © 2011-2022 走看看