1.js代码如下

var sdata = "";
$(function(){
var pathdoc = path.split(".");
var explorer =navigator.userAgent ;
if(pathdoc[1]=="pdf"){
$("#printid").attr("src","../file_FileDownload_prints.action?path="+path);
}
if(pathdoc[1]=="doc"){
if((window.ActiveXObject || "ActiveXObject" in window)){
$("#printid").hide();
$("#1c").show();
var r = $("#1c");
var y = {};
//把自定义控件word 的各个属性存到数组中
y['id'] = r.attr("id");
y['ctype'] = 'word';
y['height'] = r.attr("height");
y['width'] = r.attr("weight");
y['uname'] = '';
y['ucode'] = '';
y['ctime'] = webform.getTime();
var cJ= webform;
if (cJ) {
y['uname'] = cJ.getUserName();
y['ucode'] = cJ.getUser();
cJ = null
}
//定义一个新的office方法,将属性数组y闯过去
var cT = new Office(y);
g_ctrls[r.attr("id")] = cT;
cT.render(r);
}else{
webform.confirm("是否下载word打印?",downloadword,"","","",wordclose);
}
}

})

function downloadword(){
$("#printid").attr("src","../file_FileDownload_prints.action?path="+path);
$(parent.document).find(".co-win-gray").hide();
$(parent.document).find(".co-win-uploaddiv").hide();
}

function wordclose(){
$(parent.document).find(".co-win-gray").hide();
$(parent.document).find(".co-win-uploaddiv").hide();
}

Office = function(c) {
this.divid = c['id'];
this.myobj = null;
this.ctype = c['ctype'];
this.shost = window.location.href.substr(0, window.location.href.lastIndexOf('cops'));
//word控件打开的时候执行的事件
this.openFile = function() {
try{
var a = '';
a = this.shost+"/file_FileDownload_fileUploadword.action?path="+path;
try {
//文件名为空,打开后台原始给出的文件
if (this.ctype == 'word') {
this.myobj.Open(a, true, "Word.Document");
}
} catch (e) {
a = '';
}
if (a == '') {
return;
}
//this.myobj封装好的方法
/*this.myobj.ProtectDoc(0, 2, "0x0xx0x0x0x");*/
/*this.myobj.ShowRevisions(1);
this.myobj.SetTrackRevisions(1);
this.myobj.SetCurrUserName(c['uname']);
this.myobj.SetCurrTime(c['ctime']);
this.myobj.Titlebar = false;*/
/*this.myobj.Menubar = false;*/
a = '';
}catch(e){
return;
}
}
//表单加载后执行的事件,执行打开word
this.render = function(a) {
a.append('<object id="' + c['id'] + 'x' + '" name="' + c['id'] + 'x' + '" style="visibility:visible;left: 0px; width: 100%; top: 0px; height: 100%;" classid="clsid:00460182-9E5E-11D5-B7C8-B8269041DD57" codebase="dsoframer.ocx#version=2,3,0,1"><PARAM NAME="_ExtentX" VALUE="19923"><PARAM NAME="_ExtentY" VALUE="16325"><PARAM NAME="BorderColor" VALUE="-2147483632"><PARAM NAME="BackColor" VALUE="-2147483643"><PARAM NAME="ForeColor" VALUE="-2147483640"><PARAM NAME="TitlebarColor" VALUE="-2147483635"><PARAM NAME="TitlebarTextColor" VALUE="-2147483634"><PARAM NAME="BorderStyle" VALUE="1"><PARAM NAME="Titlebar" VALUE="0"><PARAM NAME="Toolbars" VALUE="1"><PARAM NAME="Menubar" VALUE="1"><param name="_ExtentX" value="21458"><param name="_ExtentY" value="6350"><param name="BorderColor" value="-2147483632"><param name="BackColor" value="-2147483643"><param name="ForeColor" value="-2147483640"><param name="TitlebarColor" value="-2147483635"><param name="TitlebarTextColor" value="-2147483634"><param name="BorderStyle" value="1"><param name="Titlebar" value="0"><param name="Toolbars" value="1"><param name="Menubar" value="1"></object>');
try{
this.myobj = document.all[c['id'] + 'x'];
this.openFile();
window.scrollTo(c['height'])
}catch(e){
return;
}
}
};

2.java后台代码如下

public void fileUploadword() throws IOException{
if(getWriter() == false) return;
String path = request.getParameter("path");
path = Resource.getValue("temp")+ "Temp\\"+path;
//out.write(relativelyPath);
OpenFileByStream(path,true);
}

public void OpenFileByStream(String strUrl,Boolean isLocal) {

if(isLocal != true){
strUrl = request.getRealPath(strUrl.substring(strUrl.indexOf('/') + 1)).replace("\\", "/");
try {
strUrl = java.net.URLDecoder.decode(strUrl, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}

File fi = new File(strUrl);
boolean fileIs = (fi.exists());
if (fileIs) { //如果文件存在
response.reset();
response.setCharacterEncoding("gb2312");
// response.addHeader("WWW-Authenticate", "BASIC");
response.setHeader("WWW-Authenticate", "BASIC");
// response.setHeader("Cache-Control", "no-cache");
// response.setHeader("Pragma", "no-cache");

String extName = strUrl.substring(strUrl.lastIndexOf("."),
strUrl.length()).toUpperCase(); //后缀名转换为大写
boolean strName = (extName.endsWith(".DOC")
|| extName.endsWith(".DOCX") || extName.endsWith(".PDF")
|| extName.endsWith(".PPT") || extName.endsWith(".PPTX")
|| extName.endsWith(".TXT") || extName.endsWith(".XLS")
|| extName.endsWith(".XLSX") || extName.endsWith(".BMP")
|| extName.endsWith(".GIF") || extName.endsWith(".IEF")
|| extName.endsWith(".JPEG") || extName.endsWith(".JPG")
|| extName.endsWith(".PNG") || extName.endsWith(".TIFF")
|| extName.endsWith(".TIF"));

if (strName) {
if (".DOC".equals(extName)) {
response.setHeader("Content-type","application/msword");
} else if (".DOCX".equals(extName)) {
response.setHeader("Content-type","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
} else if (".PDF".equals(extName)) {
response.setHeader("Content-type","application/pdf");
} else if (".TXT".equals(extName)) {
response.setHeader("Content-type","text/html");
} else if (".XLS".equals(extName)) {
response.setHeader("Content-type","application/vnd.ms-excel");
} else if (".XLSX".equals(extName)) {
response.setHeader("Content-type","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
} else if (".PPT".equals(extName)) {
response.setHeader("Content-type","application/vnd.ms-powerpoint");
} else if (".PPTX".equals(extName)) {
response.setHeader("Content-type","application/vnd.openxmlformats-officedocument.presentationml.presentation");
} else if (".BMP".equals(extName)) {
response.setHeader("Content-type","image/bmp");
} else if (".GIF".equals(extName)) {
response.setHeader("Content-type","image/gif");
} else if (".IEF".equals(extName)) {
response.setHeader("Content-type","image/ief");
} else if (".JPEG".equals(extName)) {
response.setHeader("Content-type","image/jpeg");
} else if (".JPG".equals(extName)) {
response.setHeader("Content-type","image/jpeg");
} else if (".PNG".equals(extName)) {
response.setHeader("Content-type","image/png");
} else if (".TIFF".equals(extName)) {
response.setHeader("Content-type","image/tiff");
} else if (".TIF".equals(extName)) {
response.setHeader("Content-type","image/tif");
}

/*
* try { TransmitFile.downLoad(response, strUrl);
* response.flushBuffer(); } catch (Exception e) {
* e.printStackTrace(); }
*/

BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
response.reset();
response.setCharacterEncoding("gb2312");
response.setContentType("application/x-msdownload");

String filename = strUrl.substring(
strUrl.lastIndexOf("/") + 1, strUrl.length());

// response.setHeader("Content-Disposition","attachment;filename="+new
// String(filename.getBytes("gb2312"),"iso8859-1"));
response.setHeader("Content-Disposition", "filename="
+ new String(filename.getBytes("gb2312"),
"iso8859-1"));
bis = new BufferedInputStream(new FileInputStream(strUrl));

bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesread;
while (-1 != (bytesread = bis.read(buff, 0, buff.length))) { //读取文件
bos.write(buff, 0, bytesread);
}
response.flushBuffer(); //将缓冲区的内容输出出来
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close(); //关闭流
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close(); //关闭流
} catch (IOException e) {
e.printStackTrace();
}
}
}
// out.flush();
// out.close();
} else {
out.write("The file type is not supported in view.");
}
}
else{
out.write("The file is not exist.");
}
}、

word在线问题的更多相关文章

  1. word在线编辑\生成图片(包含截图与合并)

    1.业务原因 word编辑后的文章复制到html编辑器(fck等)会发生排版错乱的情况,于是混沌了.需要有一个新的方法来终结,于是产生了word能不能在线编辑,后台保存,前台显示灯一系列问题. 2.首 ...

  2. 借助flexpaper实现word在线预览和打印

    为了实现word能够在web上尽量以原始的排版样式展现出来,选择基于activex控件的方式太过于依赖某种浏览器,并且存在可能需要花费金钱购买相应的控件产品:于是借助flexpaper这种flash展 ...

  3. pdf转word在线转换器

    昨天大学辅导员联系我让我pdf转word,一番搜索终于找到一款免费好用的在线转换器,亲测好使免费

  4. 实现pdf word在线浏览和下载

    这篇实现的是在线展示pdf和word并且不能显示下载和打印按钮 一 下载功能: 因为html5给a标签新添加了一个属性download,这个属性可以直接实现下载文件的功能:<a href=&qu ...

  5. 实现word在线预览 有php的写法 也有插件似

    <?php //header("Content-type:text/html;charset=utf-8"); //word转html 展示 $lj=$_GET['file' ...

  6. [转载]java开发实现word在线编辑及流转

    OA公文流转系统主要用于处理企业日常工作中内外部的各种公文,包括了公文的拟稿.审批.传阅.公告.归档,多层上级可以对下级撰写的公文进行逐级审批或修改,待最高级人员确认无误后即可进行核稿和发文等操作,最 ...

  7. [原创]java开发实现word在线编辑及流转

    OA公文流转系统主要用于处理企业日常工作中内外部的各种公文,包括了公文的拟稿.审批.传阅.公告.归档,多层上级可以对下级撰写的公文进行逐级审批或修改,待最高级人员确认无误后即可进行核稿和发文等操作,最 ...

  8. word在线预览编辑器

    https://blog.csdn.net/liuli283/article/details/73776685 https://blog.csdn.net/mxljiayou/article/deta ...

  9. php实现word在线浏览功能。

    http://laoniangke.com/php/2012/10/08/php-doc-webview.html

随机推荐

  1. AndroidStudio下gradle的入门介绍与使用

    參考: 网易云加密:http://apk.aq.163.com 网易云捕:http://crash.163.com 1 Groovy Groovy 是没有类型的 Java 代码 ,语法更简洁.形式有点 ...

  2. [基础规范]JavaBeans规范

    本文来自维基百科:http://en.wikipedia.org/wiki/JavaBeans#JavaBean_conventions JavaBeans是Java语言中能够反复使用的软件组件,它们 ...

  3. hbase分布式集群搭建

    hbase和hadoop一样也分为单机版.伪分布式版和完全分布式集群版本,这篇文件介绍如何搭建完全分布式集群环境搭建. hbase依赖于hadoop环境,搭建habase之前首先需要搭建好hadoop ...

  4. 「mysql优化专题」90%程序员没听过的存储过程和存储函数教学(7)

    一.MYSQL储存过程简介(技术文): 储存过程是一个可编程的函数,它在数据库中创建并保存.它可以有SQL语句和一些特殊的控制结构组成.当希望在不同的应用程序或平台上执行相同的函数,或者封装特定功能时 ...

  5. 在jQuery中使用canvas时遇到的问题

    正常的情况下一般在JavaScript中使用canvas,会用到如下代码: var canvas=document.getElementById("canvas"); var co ...

  6. 【java设计模式】【创建模式Creational Pattern】简单工厂模式Simple Factory Pattern(静态工厂方法模式Static Factory Method Pattern)

    public class Test { public static void main(String[] args){ try{ Factory.factory("A").doSt ...

  7. HTML基础教程-简介

    关于html5笔记前言 之前有在W3school学习过html5以及javascript.为了和大家一块学习,为了回顾这些遗忘的基础,现在我把之前自己整理的笔记共享给大家.希望大家共同进步. HTML ...

  8. 33 款主宰 2017 iOS 开发的开源库

    推荐一篇文章 改文章汇聚了现在主流的一些三方框架,很值得一看 https://mp.weixin.qq.com/s/ICodliohtzbmA-eLKRFT-Q

  9. SQL Server AlwaysOn添加监听器失败

    标签:MSSQL/ 一.错误描述 1.群集服务未能使群集服务或应用程序“Alwayson22”完全联机或脱机.一个或多个资源可能处于失败状态.这可能会影响群集服务或应用程序的可用性 2.群集服务中的群 ...

  10. C#Lambda表达式Aggregate的用法及内部运行方式的猜想

    , , , , }; // 其和为15 var count = nums.Aggregate((body, next) => { // 注意,nums的元素个数至少一个以上(但如果是有seed的 ...