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. Django中多表查询思路

    需求: 1.有一张文章表和一张评论表 2.两张表的关系是一对多 3.规则:若是有新评论,则将对应的文章置顶,若是有新文章则将新文章置顶. 思路: 在文章表中增加一个最后评论时间的字段.然后采用分组排序 ...

  2. Python爬虫(十四)_BeautifulSoup4 解析器

    CSS选择器:BeautifulSoup4 和lxml一样,Beautiful Soup也是一个HTML/XML的解析器,主要的功能也是如何解析和提取HTML/XML数据. lxml只会局部遍历,而B ...

  3. 《Deep Learning》译文 第一章 前言(中) 神经网络的变迁与称谓的更迭

    转载请注明出处. 第一章 前言(中) 1.1 本书适合哪些人阅读? 能够说本书的受众目标比較广泛,可是本书可能更适合于例如以下的两类人群.一类是学习过与机器学习相关课程的大学生们(本科生或者研究生). ...

  4. 【cogs 597】【dp】交错匹配

    597. 交错匹配 ★☆ 输入文件:crossa.in 输出文件:crossa.out 简单对照 时间限制:1 s 内存限制:128 MB [问题描写叙述] 有两行自然数. UP[1..N] . DO ...

  5. 游戏AI-行为树理论及实现

    从上古卷轴中形形色色的人物,到NBA2K中挥洒汗水的球员,从使命召唤中诡计多端的敌人,到刺客信条中栩栩如生的人群.游戏AI几乎存在于游戏中的每个角落,默默构建出一个令人神往的庞大游戏世界. 那么这些复 ...

  6. 基于Office 365的随需应变业务应用平台

    作者:陈希章 发表于 2017年9月7日 这是我去年10月底在微软技术大会(Microsoft Ignite 2016) 上面的演讲主题,承蒙大家抬爱,也沾了前一场明星讲师的光,我记得会场几乎是满座. ...

  7. 配置SQL Server on Linux(1)

    1. 背景 SQL Server一般是在安装过程中进行相关的配置,安装完成之后,再去修改有一些配置就比较麻烦,比如更改SQL Server实例级别的排序规则.但在Linux下,安装过程并没有很多可以配 ...

  8. DotNetCore跨平台~System.DrawingCore部署Linux需要注意的

    回到目录 你在windows上使用图像组件没有任务问题,但部署到linux之后,将注意以下几点: 安装nuget包ZKWeb.System.Drawing 项目里还是引用System.DrawingC ...

  9. DataBase MongoDB高级知识

    MongoDB高级知识 一.mongodb适合场景: 1.读写分离:MongoDB服务采用三节点副本集的高可用架构,三个数据节点位于不同的物理服务器上,自动同步数据.Primary和Secondary ...

  10. Java.util.Map排序输出

    在java的众多Map实现中,Map基本上是不能保证顺序的(LinkedHashMap可以保证插入顺序或者访问顺序,TreeMap默认按照key升序但可以自定义Comparator),在开发过程中当数 ...