java 查看word文档内容_JAVA实现Word文档形式打开查看的内容

标签:

我对这个功能的理解是:拿到你想要显示的信息,写入到一个临时文件当中去以便插件进行编辑。把临时文件的相对路径传到页面去。页面拿到这个要显示的文档的相对路径对文档进行编辑在Word文档里面显示出来

后台代码部分:

@RequestMapping("check")

public String check(String wid,Model model,HttpServletResponse response,HttpServletRequest request) throws IOException{

UUidUtil uuid = new UUidUtil();

String uid = uuid.getUid();//去掉"-"的32位uuid

String fileName = "";//文件名称

String fileUrl = "";//文件路径

String absoluteOfficeFileDir = request.getServletContext().getRealPath("/")+ "resources/uploadOfficeFile"; //office文件的绝对路径

String relativeOfficeFileUrl = "../resources/uploadOfficeFile"; //office文件访问的相对路径

//读取内容写入临时文件,以便插件在线编辑

byte fileBody[] = new byte[10240];

Words word = wordsBiz.getWordByWid(wid);

fileName = word.getName()+".docx";

fileBody = word.getDesc().getBytes();

fileUrl = relativeOfficeFileUrl+"/"+uid+fileName;//相对路径,访问用

String inFileUrl= absoluteOfficeFileDir+ "/" +uid+fileName;//绝对路径,io操作所用

FileOutputStream fs = new FileOutputStream(inFileUrl);

fs.write(fileBody);

fs.flush();

fs.close();

model.addAttribute("fileUrl", fileUrl);

model.addAttribute("word", word);

return "wordscheck";

}

前台页面部分:

pageEncoding="UTF-8"%>

office文档编辑

文 件 ID:文件名称: 

//重点的JS 必须要加载的

var OFFICE_CONTROL_OBJ;//控件对象

var IsFileOpened; //控件是否打开文档

var fileType;

var fileTypeSimple;

function load(fileUrl){

alert(fileUrl);

OFFICE_CONTROL_OBJ = document.all("TANGER_OCX");//浏览文档控件的加载必须要有的

NTKO_OCX_OpenDoc(fileUrl);//需要的内容加载进文档控件

}

function NTKO_OCX_OpenDoc(fileUrl) {

OFFICE_CONTROL_OBJ.BeginOpenFromURL(fileUrl);

}

《ntkoofficecontrol.js》重点代码

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘

document.write(‘codebase="http://www.ntko.com/control/officecontrol/OfficeControl.cab#version=5,0,2,7" width="100%" height="100%"> ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘ ‘);

document.write(‘不能装载文档控件。请确认你可以连接网络或者检查浏览器的选项中安全设置。安装演示产品 ‘);

document.write(‘

‘);

标签:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值