2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享

作者 : admin 本文共13702个字,预计阅读时间需要35分钟 发布时间: 2024-06-16 共1人阅读

最后

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(1)

由于文档内容过多,为了避免影响到大家的阅读体验,在此只以截图展示部分内容

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

}

}

this.WebSetMsgByName(“USERNAME”, this.UserName); // 加载UserName

this.WebSetMsgByName(“FILENAME”, this.FileName); // 加载FileName

this.WebSetMsgByName(“FILETYPE”, this.FileType); // 加载FileType

this.WebSetMsgByName(“RECORDID”, this.RecordID); // 加载RecordID

this.WebSetMsgByName(“EDITTYPE”, this.EditType); // 加载RecordID

this.WebSetMsgByName(“OPTION”, “LOADFILE”); // 发送请求LOADFILE

从jsp页面中之前定义属性获取值。

if (this.LOADFILE(httpclient)) // Http下载服务器文件

this.LOADFILE(httpclient))方法从服务器开始下载文件,代码中

this.LOADFILE = function(httpclient)

{

this.Status =

“”;

httpclient.ShowProgressUI =

this.ShowWindow;

this.ConsoleOut(

“ 开始打开链接…”);

if (httpclient.Open(

this.HttpMethod.Post,

this.WebUrl,

false))

// true

// 异步方式

// false同步

{

this.ConsoleOut(

“ 链接打开成功,开始进行数据包发送…”);

// 这里采用异步方式打开文档

if (httpclient.Send()) {

this.ConsoleOut(

“ 数据包发送成功…状态值:”+httpclient.GetResponseHeader(

“MsgError”));

if (httpclient.GetResponseHeader(

“MsgError”) ==

“404”) {

this.ConsoleOut(

“ 后台未找到对应文档,开始创建一个空白文档…”);

this.CreateFile();

this.ConsoleOut(

“ 空白文档创建成功…”);

this.getOfficeVersion();

// 打开文档后,判断当前office版本

httpclient.Clear();

return

true;

}

this.ConsoleOut(

“ 开始将后台文档保存到本地…”);

/*

* , Math.round(Math.random() * 100000)

*/

if (

this.hiddenSaveLocal(httpclient,

this,

false,

false)) {

var mSaveResult =

this

.WebOpenLocalFile(

this.DownloadedFileTempPathName);

if (mSaveResult ==

  1. {

// 打开本地磁盘文件

this.ConsoleOut(

“ 文档打开成功…”);

this.getOfficeVersion();

// 打开文档后,判断当前office版本

return

true;

}

else

if(mSaveResult ==

1){

var windows = window.confirm(

“可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else

if(mSaveResult ==

2){

var windows = window.confirm(

“没有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else

if(mSaveResult ==

3){

var windows = window.confirm(

“没有权限导致文档打开失败,请用管理员身份运行浏览器后重试”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“没有权限导致文档打开失败,请用管理员身份运行浏览器后重试”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else

if(mSaveResult ==

4){

var windows = window.confirm(

“文件可能损坏,请确定服务器文档是否已经损坏”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“文件可能损坏,请确定服务器文档是否已经损坏”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else

if(mSaveResult ==

5){

var windows = window.confirm(

“未安装Office或者注册表有损坏”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“未安装Office或者注册表有损坏”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else

if(mSaveResult ==

6){

var windows = window.confirm(

“文件被占用,请结束Office进程后重试”

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“文件被占用,请结束Office进程后重试”;

if (windows ==

  1. {

window.close();

return

false;

}

}

else {

this.ConsoleOut(

” 打开文档时未知错误!错误码为: “

  • mSaveResult);

var windows = window.confirm(

“打开文档时未知错误!错误码为: “

  • mSaveResult

“\r\r单击“确定”关闭。单击“取消”继续。”);

this.Status =

“打开文档时未知错误!错误码为: “

  • mSaveResult;

if (windows ==

  1. {

window.close();

return

false;

}

}

}

else {

// 失败后,this.Status的值由hiddenSaveLocal返回

this.Status =

“保存文档到本地 失败”;

return

false;

}

}

else {

this.Status =

“数据包发送失败!请检查链接<” +

this.WebUrl +

“>是否正确或网络是否畅通。”;

return

false;

}

}

else {

this.Status =

“打开链接<” +

this.WebUrl +

“>失败!请检查网络是否畅通。”;

return

false;

}

}

加载文档的原理:采用http请求的方式,采用异步来实现文档加载:if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) // true。第一个参数固定不变,是模拟http的post请求、第二个参数:this.WebUrl内放置的即使我们的后台核心处理类的地址、第三个参数是异步同步的设置;

加载文档的核心处理类:这里后台文件OfficeServer我们需要按实际业务需求更改一下,这里我直接贴我的代码,由于我们只先说文档打开,所以就只贴一部分代码了,经过http请求响应的核心处理类OfficeServer;

加载文档的核心处理方法:核心方法是protected void service(){

}

方法体:

logger.info(

“进入service方法”);

this.mCommand =

“”;

this.mFileBody =

null;

this.mFilePath = request.getSession().getServletContext().getRealPath(

“/”);

try {

if (request.getMethod().equalsIgnoreCase(

“POST”)) {

this.MsgObj.setSendType(

“JSON”);

//文件上传

this.MsgObj.Load(request);

this.mOption =

this.MsgObj.GetMsgByName(

“OPTION”);

this.mUserName =

this.MsgObj.GetMsgByName(

“USERNAME”);

//20190403

if (

this.mOption.equalsIgnoreCase(

“LOADFILE”)) {

//如果是下载模式

this.mRecordID =

this.MsgObj.GetMsgByName(

“RECORDID”);

this.mFileName =

this.MsgObj.GetMsgByName(

“FILENAME”);

this.MsgObj.MsgTextClear();

this.mFilePath =

this.mFilePath.replace(

‘\’,

‘/’);

// web跟目录

this.mFilePath =

this.mFilePath +

“upload_files”;

String finalAdd =mFilePath+

“/”+mFileName;

if(MsgObj.MsgFileLoad(finalAdd)){

System.

out.println(

“文档加载成功”);

}

else{

System.

out.println(

“文档加载失败”);

}

代码中 this.mFilePath即使你tomcat下面的附件文件夹地址

接下来是 MsgObj.MsgFileLoad方法

public boolean MsgFileLoad(String fileName) throws IOException

{

File f =

new File(fileName);

if (!f.exists()) {

throw

new FileNotFoundException(fileName);

}

ByteArrayOutputStream bos =

new ByteArrayOutputStream((

int)f.length());

BufferedInputStream in =

null;

try {

in =

new BufferedInputStream(

new FileInputStream(f));

int buf_size =

1024;

byte[] buffer =

new

byte[buf_size];

int len =

0;

while (-

1 != (len = in.read(buffer,

0, buf_size))) {

bos.write(buffer,

0, len);

}

this.mFileBody = bos.toByteArray();

return

true;

}

catch (IOException e) {

e.printStackTrace();

throw e;

}

finally {

try {

in.close();

}

catch (IOException e) {

e.printStackTrace();

}

bos.close();

}

}

我们不需要修改什么地方。直接引用官网给的demo就行。

总结:

===

一:js文件

1.1 页面中需要引入的属性设置

二:核心处理类

2.后台文件需要修改的只是将 this.mFilePath 定义为自己的tomcat附件的文件夹地址

成果展示


2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(2)

页面展示

左上角根据实际业务需求,只开放了打开文档(打开文档之前提过,页面初始化,带着提前准备的参数,已经打开)、保存到服务器两个功能。


打开文档之后,可以在线编辑文档,word自己带的功能,在这里全部都适用,这点不用担心。

修改文档之后就开始保存了,接下来就是保存文档的正题。


4.2 在线编辑以及服务器保存实现


老样子,直接贴代码

OpenAndSave_Word.jsp

//保存文档

function

SaveDocument() {

if (WebOfficeObj.WebSave()) {

//交互OfficeServer的OPTION=“SAVEFILE”

WebOfficeObj

.WebClose();

window

.close();

}

else {

alert(WebOfficeObj.Status);

StatusMsg(WebOfficeObj.Status);

}

}

WebOffice.js

处理方法:

方法体:

this.ConsoleOut(

“ 保存文件…”);

this.ConsoleOut(

“ 开始…”);

this.Status =

“”;

var httpclient =

this.obj.Http;

// 设置http对象

httpclient.Clear();

//一如既往,这里是属性赋值

this.WebSetMsgByName(

“USERNAME”,

this.UserName);

this.WebSetMsgByName(

“RECORDID”,

this.RecordID);

this.WebSetMsgByName(

“TEMPLATE”,

this.Template);

this.WebSetMsgByName(

“SUBJECT”,

this.Subject);

this.WebSetMsgByName(

“AUTHOR”,

this.Author);

this.WebSetMsgByName(

“HTMLPATH”,

this.HTMLPath);

this.WebSetMsgByName(

“FILETYPE”,

this.FileType);

this.WebSetMsgByName(

“OPTION”,

“SAVEFILE”);

this.WebSetMsgByName(

“FILENAME”,

this.FileName);

// 加载FileName

//判断是否保存空文档的方法

if(

this.WebSetAllowEmpty()){

//文档保存到本地

var mSaveResult =

this.WebSaveLocalFile(

this.getFilePath()

this.FileName);

if (!(mSaveResult ==

0)) {

this.ConsoleOut(

“ 保存本地文档失败!错误代码为:” + mSaveResult);

this.Status =

“保存本地文档失败!错误代码为:” + mSaveResult;

return

false;

}

}

else{

alert(

“文档没有内容,是否确定保存”);

}

this.ConsoleOut(

“ 将文档保存到本地成功…”);

this.sendMode =

“SaveFile”;

this.ConsoleOut(

“ 开始将文档保存到服务器…”);

// 判断本地文件是否大于指定的文件大小,如果大于不保存

if (

this.WebSetMaxFileSize(

this.FilePath +

this.FileName)) {

//这里需要将这个值传递到后台

var add =

this.FilePath +

this.FileName;

//这里需要将本地隐藏目录传递到后台。如果单一传递路径,json编译会出错,需要修改一下

//var add = add.replace(“\”,“\\”);

var arrayStr = add.split(

“\”);

this.WebSetMsgByName(

“FILEPATH”,arrayStr);

//开始保存到服务器了

if (

this.SAVEFILE(httpclient,

this.FilePath +

this.FileName)) {

this.ConsoleOut(

“ 成功将文档保存到服务器…”);

var ISO = httpclient.GetResponseHeader(

“ISO”);

// 获取返回值

this.Status =

“成功将文档保存到服务器”;

return

true;

}

else {

//STATUS 由this.SAVEFILE返回

return

false;

}

}

else {

this.Status =

“保存失败:MaxFileSize只能允许保存:<” +

this.MaxFileSize /

1024

“>” +

“M”;

return

false;

}

这里得插几句我的思路和理解了。

所谓的在线编辑保存就是从服务器先获得你需要修改的文档也就是文档模板,之后将模板加载出来,这个时候WebOffice会将文档存放在一个叫做down的目录中(win+r 输入 %appdata% 看到一个)

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(3)

文档加载隐藏目录

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(4)

隐藏目录

之后我们开始文档编辑,编辑完,WebOffice会将这个形成的临时文件存放到隐藏目录叫做up的文件夹中,我们点击保存的时候,如果实际需求是不能覆盖原先模板,我们将存放在up中的文件实际完整地址获取到,将文件上传到我们的tomcat附件目录中,后期我们在数据库中通过版本控制,实现每次加载的模板总是最新的模板(最后修改人上传的文档模板)。

说了几句废话,开始继续贴代码

OfficeServer.java中

//20190403 文档在线编辑保存

else

if (

this.mOption.equalsIgnoreCase(

“SAVEFILE”)) {

this.mRecordID =

this.MsgObj.GetMsgByName(

“RECORDID”);

this.mFileName =

this.MsgObj.GetMsgByName(

“FILENAME”);

this.mFileType =

this.MsgObj.GetMsgByName(

“FILETYPE”);

String userName =

this.MsgObj.GetMsgByName(

“USERNAME”);

//这里这个路径 必须特殊处理掉

String mFilePath =

this.MsgObj.GetMsgByName(

“FILEPATH”);

this.mFileBody =

this.MsgObj.MsgFileBody();

this.mFileSize =

this.MsgObj.MsgFileSize();

this.mFileDate =

this.DbaObj.GetDateTime();

this.MsgObj.MsgTextClear();

//获取tomcat下面附件的地址

this.mFilePath =

this.mFilePath.replace(

‘\’,

‘/’);

// web跟目录

this.mFilePath =

this.mFilePath +

“upload_files”+

“”;

String newPath =

this.mFilePath+

“/”+mFileName;

//得到旧的文件地址(文件的隐藏目录) 。

String oldPath =mFilePath.replace(

‘,’,

‘/’);

//自己定义的方法,主要是存数据库中

if (SaveFile(

this.mRecordID,

this.mFileName,

this.mFileType,

this.mFileBody,

this.mFileSize,

this.mFileDate,userName, newPath,oldPath)) {

System.

out.println(

“文档保存成功”);

}

else{

System.

out.println(

“文档保存失败”);

}

}

这个方法主要是实现:获取自己想要存入数据库中的各个属性值、获得两个文件存储的完整目录,为后期上传做准备。

private

boolean SaveFile(

String mRecordID,

String mFileName,

String mFileType,byte [] mFileBody,

int mFileSize,

String mFileDate,

String userName,

String newPath,

String oldPath ) {

boolean mResult =

false;

try {

Connection myconn = ConnectionManager.getDefaultConnection();

try {

myconn.setAutoCommit(

false);

Statement stmt = myconn.createStatement();

ResultSet rs =

null;

//参数赋值

this.mFileType = mFileType;

this.mUserName = userName;

this.mFileName = mFileName;

this.mFileSize = this.MsgObj.MsgFileSize();

String mxId = Asstool.getMaxHirisunId();

String uploadDate = Asstool.getSystemDatetimetostring();

try {

//判断文档之前是否上传过

String Sql =

“select t.conid from ulob.slavefiles t “

” where t.pk_id='”+mRecordID+

“’ “

” order by t.uploaddate desc”;

List

list = SingleTableOperation.getSimpleRecords(Sql);

if(

list.size()>

0){

//此文档之前上传过

//取出主表id 去查询明细

String conId = ((

List)(

list.get(

0))).get(

0).toString();

//用之前存在子表中的字段更新即将插入的数据

String sqlSelectMx =

“select t1.* from ulob.slavefiles_version t1 “

” where t1.recordid='”+conId+

“’ “

” order by t1.history desc”;

List listMx = SingleTableOperation.getSimpleRecords(sqlSelectMx);

if(listMx.size()>

0){

List listOne =(

List) listMx.get(

0);

//ulob.slavefiles 主键 。作为子表的引用

String recordId = listOne.get(

0).toString();

//人名

String userName1 = this.mUserName;

//版本号

String history = listOne.get(

5).toString();

//表id

String Mxid = mxId;

//大小

int fileSize = this.mFileSize;

String fileName = (

new Date()).getTime()+recordId+this.mFileType;

//路径不变。但是得截取只要纯路径 不含名字

String filePath = listOne.get(

3).toString();

filePath = filePath.substring(

0,filePath.lastIndexOf(

“/”));

filePath = filePath+

“/”+fileName;

//

String inedit = listOne.get(

9).toString();

try {

//在线编辑 分为两步:第一步插入数据库 。第二步复制隐藏目录下的文件到 系统的附件文件夹

String insertSql =

” insert into ulob.slavefiles_version “

” (recordid,filedate,filebody,filepath,username,history,id,filesize,filename,isedit,edituser,editdata ) “

” values(‘”+recordId+

“‘,to_date(’”+uploadDate+

“‘,‘yyyy-mm-dd hh24:mi:ss’),empty_blob(),’”+filePath+

“‘,’”+userName1+

“‘,’”

String.valueOf((

Integer.parseInt(history)+

1))+

“‘,’”+Mxid+

“‘,’”+fileSize+

“‘,’”+fileName+

“‘,’”+inedit+

“‘,’”+userName+

“‘,to_date(’”+uploadDate+

“‘,‘yyyy-mm-dd hh24:mi:ss’)) “;

//更新

TableOperation.ExecuteUpdateSQL(insertSql);

rs = stmt

.executeQuery(

“select filebody from ulob.slavefiles_version t where=’”

  • Mxid +

“’ for update”);

//实现在线编辑的第一部分:

if (rs.next()) {

Blob blob = rs.getBlob(

1);

OutputStream out = ((oracle.sql.BLOB) blob)

.getBinaryOutputStream();

byte[] b =

new byte[((oracle.sql.BLOB) blob)

.getBufferSize()];

File file =

new File(oldPath);

InputStream fis =

new FileInputStream(file);

int len =

0;

while ((len = fis.read(b)) !=

-1)

out.write(b,

0, len);

out.close();

myconn.commit();

mResult=

true;

}

}

catch (

Exception e) {

// TODO: handle exception

e.printStackTrace();

}

finally {

myconn.close();

this.MsgObj.MsgFileSave(filePath);

//zhazha

}

}

最后

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(5)

2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享插图(6)

由于文档内容过多,为了避免影响到大家的阅读体验,在此只以截图展示部分内容

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

mFileName,

this.mFileType,

this.mFileBody,

this.mFileSize,

this.mFileDate,userName, newPath,oldPath)) {

System.

out.println(

“文档保存成功”);

}

else{

System.

out.println(

“文档保存失败”);

}

}

这个方法主要是实现:获取自己想要存入数据库中的各个属性值、获得两个文件存储的完整目录,为后期上传做准备。

private

boolean SaveFile(

String mRecordID,

String mFileName,

String mFileType,byte [] mFileBody,

int mFileSize,

String mFileDate,

String userName,

String newPath,

String oldPath ) {

boolean mResult =

false;

try {

Connection myconn = ConnectionManager.getDefaultConnection();

try {

myconn.setAutoCommit(

false);

Statement stmt = myconn.createStatement();

ResultSet rs =

null;

//参数赋值

this.mFileType = mFileType;

this.mUserName = userName;

this.mFileName = mFileName;

this.mFileSize = this.MsgObj.MsgFileSize();

String mxId = Asstool.getMaxHirisunId();

String uploadDate = Asstool.getSystemDatetimetostring();

try {

//判断文档之前是否上传过

String Sql =

“select t.conid from ulob.slavefiles t “

” where t.pk_id='”+mRecordID+

“’ “

” order by t.uploaddate desc”;

List

list = SingleTableOperation.getSimpleRecords(Sql);

if(

list.size()>

0){

//此文档之前上传过

//取出主表id 去查询明细

String conId = ((

List)(

list.get(

0))).get(

0).toString();

//用之前存在子表中的字段更新即将插入的数据

String sqlSelectMx =

“select t1.* from ulob.slavefiles_version t1 “

” where t1.recordid='”+conId+

“’ “

” order by t1.history desc”;

List listMx = SingleTableOperation.getSimpleRecords(sqlSelectMx);

if(listMx.size()>

0){

List listOne =(

List) listMx.get(

0);

//ulob.slavefiles 主键 。作为子表的引用

String recordId = listOne.get(

0).toString();

//人名

String userName1 = this.mUserName;

//版本号

String history = listOne.get(

5).toString();

//表id

String Mxid = mxId;

//大小

int fileSize = this.mFileSize;

String fileName = (

new Date()).getTime()+recordId+this.mFileType;

//路径不变。但是得截取只要纯路径 不含名字

String filePath = listOne.get(

3).toString();

filePath = filePath.substring(

0,filePath.lastIndexOf(

“/”));

filePath = filePath+

“/”+fileName;

//

String inedit = listOne.get(

9).toString();

try {

//在线编辑 分为两步:第一步插入数据库 。第二步复制隐藏目录下的文件到 系统的附件文件夹

String insertSql =

” insert into ulob.slavefiles_version “

” (recordid,filedate,filebody,filepath,username,history,id,filesize,filename,isedit,edituser,editdata ) “

” values(‘”+recordId+

“‘,to_date(’”+uploadDate+

“‘,‘yyyy-mm-dd hh24:mi:ss’),empty_blob(),’”+filePath+

“‘,’”+userName1+

“‘,’”

String.valueOf((

Integer.parseInt(history)+

1))+

“‘,’”+Mxid+

“‘,’”+fileSize+

“‘,’”+fileName+

“‘,’”+inedit+

“‘,’”+userName+

“‘,to_date(’”+uploadDate+

“‘,‘yyyy-mm-dd hh24:mi:ss’)) “;

//更新

TableOperation.ExecuteUpdateSQL(insertSql);

rs = stmt

.executeQuery(

“select filebody from ulob.slavefiles_version t where=’”

  • Mxid +

“’ for update”);

//实现在线编辑的第一部分:

if (rs.next()) {

Blob blob = rs.getBlob(

1);

OutputStream out = ((oracle.sql.BLOB) blob)

.getBinaryOutputStream();

byte[] b =

new byte[((oracle.sql.BLOB) blob)

.getBufferSize()];

File file =

new File(oldPath);

InputStream fis =

new FileInputStream(file);

int len =

0;

while ((len = fis.read(b)) !=

-1)

out.write(b,

0, len);

out.close();

myconn.commit();

mResult=

true;

}

}

catch (

Exception e) {

// TODO: handle exception

e.printStackTrace();

}

finally {

myconn.close();

this.MsgObj.MsgFileSave(filePath);

//zhazha

}

}

最后

[外链图片转存中…(img-c7XDkaGK-1715689114956)]

[外链图片转存中…(img-Uwk2VvrU-1715689114957)]

由于文档内容过多,为了避免影响到大家的阅读体验,在此只以截图展示部分内容

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

本站无任何商业行为
个人在线分享 » 2024年最全金格插件WebOffice2024使用体会(1),2024年最新面试干货分享
E-->