pageoffice集成

 

pageOffice集成简述

(下列简述是跨域请求,将文件服务器中的文件下载到本地,然后打开,保存之后再次上传到服务器)

1:下载试用版本项目文件

           

         

 Samples4:

是pageOffice测试项目包,直接可在Tomcat WebApps 中运行,

访问localhost:8080/Samples4/index.html即可访问到pageOffice所有测试案例

集成文件:

          

         

lib:是集成项目所需的jar包,

web.xml是集成项目中需要在web.xml中配置的配置内容

2:集成

(1)引入相关js

(2)符合条件的文件添加事件(可将连接分开来写,互相不干扰)

3:java后台页面跳转控制

         

          

word_edit.jsp

         

         

         

(1):pageoffice服务配置,必须有

(2):pageoffice操作按钮配置,可视需求而定,

(3):后台响应返回数据

(4):通过文件类型判断打开文件所需要的模板

word_read.jsp就是在word_edit.jsp中保存操作去掉即可

word_save.jsp

如果在java中对文件进行保存可在word_edit.jsp保存设置中直接调用后台保存

tao_hong.jsp (模板后缀和要套红的后缀必须一致,否则可能导致文件损坏

<%@page import="com.jrfmail.common.util.FileUtils"%>

<%@page import="java.net.URLEncoder"%>

<%@ page language="java"

import="java.util.*,com.zhuozhengsoft.pageoffice.*,java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*"

pageEncoding="utf-8"%>

<%@page import="com.zhuozhengsoft.pageoffice.wordwriter.DataRegion"%>

<%@page import="com.zhuozhengsoft.pageoffice.wordwriter.WordDocument"%>

 

<%!

         public void copyFile(String oldPath, String newPath) {

         try {

int bytesum = 0;

int byteread = 0;

File oldfile = new File(oldPath);

if (oldfile.exists()) { //文件存在时

            InputStream inStream = new FileInputStream(oldPath); //读入原文件

            FileOutputStream fs = new FileOutputStream(newPath);

            byte[] buffer = new byte[1444];

            int length;

            while ((byteread = inStream.read(buffer)) != -1) {

                bytesum += byteread; //字节数 文件大小

                //System.out.println(bytesum);

                fs.write(buffer, 0, byteread);

            }

            inStream.close();

}

} catch (Exception e) {

System.out.println("复制单个文件操作出错");

e.printStackTrace();

}

 

         }

%>

<%

//获取需要的数据

String fileName = (String)request.getAttribute("fileName");

Integer fileId = (Integer)request.getAttribute("fileId");

Integer userId = (Integer)request.getAttribute("userId");

String userName = (String)request.getAttribute("userName");

String mbName = request.getParameter("mb");

 

 

//***************************卓正PageOffice组件的使用********************************

 PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);

 poCtrl1.setServerPage(request.getContextPath()+"/poserver.zz"); //此行必须

 poCtrl1.setCustomToolbar(false);

 poCtrl1.setSaveFilePage("word_save.do?fileId="+fileId);

 System.out.println(fileName);

 String webFileName = URLEncoder.encode(fileName, "UTF-8");

 if (mbName != null && mbName.trim() != "") {

  // 选择模板后执行套红

     

     // 复制模板,命名为正式发文的文件名:zhengshi.doc

     String templateName = request.getParameter("mb");

  System.out.print(templateName);

     String templatePath = getServletContext().getRealPath(templateName);

     String filePath = getServletContext().getRealPath("/temp/"+userId+"/" + fileName);

     //copyFile(templatePath,filePath);

     

     // 填充数据和正文内容到“zhengshi.doc”

     WordDocument doc = new WordDocument();

     //DataRegion copies = doc.openDataRegion("PO_Copies");

     //copies.setValue("6");

     DataRegion docNum = doc.openDataRegion("PO_DocNum");

    // docNum.setValue("001");

     //DataRegion issueDate = doc.openDataRegion("PO_IssueDate");

     //issueDate.setValue("2013-5-30");

    // DataRegion issueDept = doc.openDataRegion("PO_IssueDept");

     //issueDept.setValue("开发部");

     DataRegion sTextS = doc.openDataRegion("PO_STextS");

     sTextS.setValue("[word]/temp/"+userId+"/"+webFileName+"[/word]");//写公司文件的路径

     DataRegion sTitle = doc.openDataRegion("PO_sTitle");

     //sTitle.setValue("北京金瑞帆公司销售文件");

     DataRegion topicWords = doc.openDataRegion("PO_TopicWords");

     //topicWords.setValue("Pageoffice、 套红");

     poCtrl1.setWriter(doc);

     poCtrl1.webOpen(templateName, OpenModeType.docNormalEdit, userName);

 }else {

  System.out.println("/temp/"+userId+"/" + webFileName);

     poCtrl1.webOpen("/temp/"+userId+"/" + webFileName, OpenModeType.docNormalEdit, userName);

 }

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title></title>

<link href="images/csstg.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

//初始加载模板列表

function load() {

if (getQueryString("mb") != null)

document.getElementById("templateName").value = getQueryString("mb");

}

 

//获取url参数

function getQueryString(name) {

var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");

var r = window.location.search.substr(1).match(reg);

if (r != null)

            return unescape(r[2]);

else

            return null;

}

 

//套红

function taoHong() {

var mb = document.getElementById("templateName").value;

document.getElementById("form1").action = "/mail/show_word.do?id=<%=fileId%>&showType=3&mb=" + mb;

document.forms[0].submit();

}

 

//保存并关闭

function saveAndClose() {

document.getElementById("PageOfficeCtrl1").WebSave();

window.external.close();

}

</script>

</head>

<body οnlοad="load();" >

<div id="content">

            <div id="textcontent" style="width: 1000px; height: 800px;">

                <div class="flow4">

                    <span style="width: 100px;"> </span><strong>文档主题:</strong>

                    <span style="color: Red;">测试文件</span>

                    <form method="post" id="form1">

                        <strong>模板列表:</strong>

                        <span style="color: Red;"> <select name="templateName"

id="templateName" style='width: 240px;'>

                                <option value='/temp/taohong/temp2008.doc' selected="selected">

                                    模板一

                                </option>

                                <option value='/temp/taohong/temp2009.doc'>

                                    模板二

                                </option>

                                <option value='/temp/taohong/temp2010.doc'>

                                    模板三

                                </option>

                            </select> </span>

                        <span style="color: Red;"><input type="button" value="一键套红"

                                οnclick="taoHong()"/> </span>

                        <span style="color: Red;"><input type="button" value="保存关闭"

οnclick="saveAndClose()"/> </span>

                    </form>

                </div>

 

                        <%=poCtrl1.getHtmlCode("PageOfficeCtrl1")%>

            </div>

</div>

</body>

</html>

 

 

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页