如何在浏览器网页中显示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();

最新文章

  1. Angularjs+node+Mysql实现地图上特定点的定位以及附加信息展示
  2. python类定义与c#的一些区别
  3. codis配置
  4. Iphone H5上传照片被旋转
  5. Android控件_TextView(显示文本框控件)
  6. YCM的安装与配置
  7. MEF 编程指南(十):重组
  8. 当传递具有已修改行的 DataRow 集合时,更新要求有效的 UpdateCommand问题解决
  9. 学习restful 架构
  10. [python 基础] Class 一些基本概念
  11. 管理 sendmail 的邮件队列
  12. #ifdef _cplusplus
  13. 【centos6 , 6】linux 查看帮助文档:
  14. UIGestureRecognizer 手势浅析
  15. Android简易实战教程--第二十七话《自定义View入门案例之开关按钮详细分析》
  16. LaTeX 中图片格式错误情况
  17. 「学习笔记」min_25筛
  18. 探秘JS的异步单线程
  19. 使用@RequestBody将请求体映射到Action方法参数中
  20. mysql 让id字段 以1000 形式开头

热门文章

  1. treeMap,key排序,value排序
  2. [待解决]ColumnPrefixFilter 不能过滤出全部满足条件的,
  3. java+lucene中文分词,来看看百度究竟是怎么找到你想要的(十分重要,楼主幸苦之作)
  4. 给jdk配置jvm的参数
  5. Storm系统架构以及代码结构学习
  6. 从thinkphp到php到ajax
  7. php form 图片上传至服务器上
  8. 计算机视觉中的边缘检测Edge Detection in Computer Vision
  9. numpy和TensorFlow的函数
  10. Java Tomcat7性能监控与优化详解