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. 01_GIT基础、安装

     1 为什么选择GIT 分布式,强调个体 公共server压力和数据量都不会太大 速度快.灵活 随意两个开发人员之间能够非常easy的解决冲突 离线工作 每日工作备份 能够吃懊悔药 2  GIT基 ...

  2. 资深实践篇 | 基于Kubernetes 1.61的Kubernetes Scheduler 调度详解

    欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:腾讯云容器服务团队 源码为 k8s v1.6.1 版本,github 上对应的 commit id 为 b0b7a323cc5a4a ...

  3. 自学Zabbix3.8.1.2-可视化Visualisation-Graphs自定义图表

    自学Zabbix3.8.1.2-可视化Visualisation-Graphs自定义图表 自定义图表,如名称所示,提供定制功能.虽然简单的图形可以很好地查看单个项目的数据,但是它们不提供配置功能.因此 ...

  4. springboot(十五):springboot+jpa+thymeleaf增删改查示例

    这篇文章介绍如何使用jpa和thymeleaf做一个增删改查的示例. 先和大家聊聊我为什么喜欢写这种脚手架的项目,在我学习一门新技术的时候,总是想快速的搭建起一个demo来试试它的效果,越简单越容易上 ...

  5. CoreJava逻辑思维-顺时针打印自定义矩阵

    CoreJava逻辑思维-顺时针打印自定义矩阵 这两天回顾了一下刚入Java时的一些比较有意思的逻辑题,曾经也费劲脑汁的思考过的一些问题,比如百钱百鸡最简单的算法啦之类的,而今天博主想说的是一个循环打 ...

  6. 常见.NET功能代码汇总 (3)

    33,彻底关闭Excel进程 .NET中使用Excel属于使用非托管资源,使用完成后一般都要用GC回收资源,但是,调用GC的位置不正确,Excel进程可能无法彻底关闭,如下面的代码: static v ...

  7. 3. python文件操作

            5 打开文件的模式有: r,只读模式(默认). w,只写模式.[不可读:不存在则创建:存在则删除内容:] a,追加模式.[可读:   不存在则创建:存在则只追加内容:]        ...

  8. 小白的Python之路 day4 装饰器前奏

    装饰器前奏: 一.定义: 1.装饰器本质是函数,语法都是用def去定义的 (函数的目的:他需要完成特定的功能) 2.装饰器的功能:就是装饰其他函数(就是为其他函数添加附加功能) 二.原则: 1. 不能 ...

  9. Hosts文件实际应用 配置内部服务器提高访问效率和速度

    一 hosts文件的作用和介绍 https://jingyan.baidu.com/article/335530da45485e19cb41c3d6.html https://www.cnblogs. ...

  10. mentohust 使用

    可使用帮助命令 mentohust -h 或着查看 https://wenku.baidu.com/view/95c08019ff00bed5b9f31d1a.html