兰陵word导出
1.根据分类确认不同导出模板(没有分类的可以跳过)
1.JSP页面
1.确定修改的文件
根据页面路径请求地址,参数查找xml中的对应请求参数所对应的文件路径
2.添加按钮
将按钮添加到页面,可以根据需求来添加显示条件
//按钮
<c:if test="${ isCreatorFlag==true}">
<c:import url="classbutton.jsp" charEncoding="UTF-8">
<c:param name="fdId" value="${param.fdId}"/>
</c:import>
</c:if>
3.编写弹框页面
根据需求对路径添加参数
<%--按钮页面--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/resource/jsp/common.jsp"%>
<ui:button text="导出" onclick="updateInfo()" order="3" parentId="toolbar" />
<script>
function updateInfo() {
seajs.use(['sys/ui/js/dialog'], function(dialog) {
<%--指定弹框页面以及参数--%>
var url = "/cost/apply/cost_apply_zdsq/selectTemplate.jsp?fdId=${param.fdId}&fdCategory=${costApplyZdsqForm.docTemplateName}";
dialog.iframe(url, "选择导出模板", null, {width:500, height:400});
});
}
</script>
4.编写弹框页面
根据需求编写判断代码及页面生成的模板, downloadDoc(fdTemplateId) 方法为请求后端打印地址可以根据需求添加传参
<%--弹框页面--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
<style>
.category-list {
width: 100%;
height: 300px;
padding: 0;
margin: 0;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.category-list ul {
list-style-type: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.category-list li {
margin: 10px;
}
</style>
</head>
<script>
// 获取地址栏的完整URL
var url = window.location.href;
// 获取地址栏的参数部分
var params = window.location.search;
// 获取指定参数的值
function getParameterByName(name) {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(params);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function downloadDoc(fdTemplateId) {
var tableName = document.getElementById("ul").children[fdTemplateId].querySelector("span").innerText;
var fdId = getParameterByName('fdId');
var url = "/pro/word/proWordDownload.do?method=downloadWord&fdId=" + fdId + "&&type=zdsq&&tableName=" + tableName;
window.open(url, '_blank');
}
window.onload = function () {
var category = getParameterByName('fdCategory');
var li = "";
if (category == "山东水设") {
li = '<li><span>山东省水利勘测设计院有限公司</span><button onclick="downloadDoc(' + 0 + ')">选择</button> </li>';
} else if (category == "监理公司") {
li = '<li><span>山东省水利工程建设监理有限公司</span> <button onclick="downloadDoc(' + 0 + ')">选择</button></li>';
} else if (category == "水设分公司") {
li = '<li><span>山东省水利勘测设计院贵州分公司</span> <button onclick="downloadDoc(' + 0 + ')">选择</button></li>' +
'<li><span>山东省水利勘测设计院临沂分公司</span> <button onclick="downloadDoc(' + 1 + ')">选择</button></li>' +
'<li><span>山东省水利勘测设计院青岛分公司</span> <button onclick="downloadDoc(' + 2 + ')">选择</button></li>';
} else if (category == "大禹集团") {
li = '<li><span>山东大禹水务建设集团有限公司</span> <button onclick="downloadDoc(' + 0 + ')">选择</button></li>' +
'<li><span>山东省水利水电建筑工程承包有限公司</span> <button onclick="downloadDoc(' + 1 + ')">选择</button></li>';
} else if (category == "试验中心") {
li = '<li><span>山东省水利工程试验中心有限公司</span><button onclick="downloadDoc(' + 0 + ')">选择</button> </li>';
}
document.getElementById("ul").innerHTML = li;
}
</script>
<body>
<div class="category-list">
<ul id="ul">
</ul>
</div>
</body>
</html>
5.实现根据分类弹出不同模板
2.JAVA
1.找到WORD导出的Action=》ProWordDownloadAction
用找jsp页面的方式找到配置文件指定的Action
2.根据入参判断条件调用指定方法
public ActionForward downloadWord(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
TimeCounter.logCurrentTime("Action-downloadWord", true, getClass());
KmssMessages messages = new KmssMessages();
try {
String type = request.getParameter("type");
String fileName = "";
String ftlName = "";
Map<String, Object> dataMap = new HashMap<>();
if ("wzcgsqd".equals(type)) {// 物资采购申请单
fileName = "物资采购申请单.doc";
ftlName = "物资采购申请单.ftl";
dataMap = getServiceImp(request).getDataMap1(request);
} else if ("zdsq".equals(type)) {// 报销单业务人员打印
String tableName = request.getParameter("tableName");
fileName = tableName+".doc";
ftlName = "招待申请.ftl";
dataMap = getServiceImp(request).getDataMap20(request);
}
FreemarkerUtils.exportMillCertificateWord(request, response, dataMap, fileName, ftlName);
return null;
} catch (Exception e) {
messages.addError(e);
if (messages.hasError()) {
KmssReturnPage.getInstance(request).addMessages(messages).save(request);
return this.getActionForward("failure", mapping, form, request, response);
}
KmssReturnPage.getInstance(request).addMessages(messages).addButton(0).save(request);
return this.getActionForward("success", mapping, form, request, response);
}
}
3.添加相应的getDataMap21(request)
添加相应的方法到IProWordDownloadService并添加实现方法到ProWordDownloadServiceImp,修改相应的取值逻辑
获取实体类,并将参数和签名放入Map中(这里的名字要和flt文件中的名字对应起来)
@Override
public Map<String, Object> getDataMap21(HttpServletRequest request) throws Exception {
Map<String, Object> dataMap = new HashMap<>();
String fdId = request.getParameter("fdId");
IKmReviewMainService kmReviewMainService = (IKmReviewMainService) SpringBeanUtil.getBean("kmReviewMainService");
KmReviewMain kmReviewMain = (KmReviewMain) kmReviewMainService.findByPrimaryKey(fdId, null, true);
if (kmReviewMain != null) {
Map<String, Object> data = kmReviewMain.getExtendDataModelInfo().getModelData();
// 项目名称
dataMap.put("项目名称", data.get("fd_3c17f9577a695a") != null ? data.get("fd_3c17f9577a695a") : "");
// 申请注册师信息
List<Map<String, Object>> tableList = new ArrayList<>();
List list = (ArrayList) data.get("fd_3c17fb5a9c61a0");
List<String> zcsIds = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> tableMap = new HashMap<>();
//申请注册师类别
Map map = (Map) list.get(i);
String fdZcslb = (String) map.get("fd_3c17fb7ec1bc7c");
tableMap.put("fdZcslb", fdZcslb == null ? "" : fdZcslb);
Map zcgcs = (Map) map.get("fd_3c17fb7c5a34ca");
String name = (String) zcgcs.get("name");
//姓名
tableMap.put("fdName", name == null ? "" : name);
tableList.add(tableMap);
//添加Id获取签名
zcsIds.add((String) zcgcs.get("id"));
}
dataMap.put("datilList", tableList);
List<LbpmAuditNote> lbpmAuditNoteList = getLbpmAuditNoteService().findByModelId(fdId, new RequestContext());
List zcsqmList = new ArrayList();
for (int i = 0; i < lbpmAuditNoteList.size(); i++) {
LbpmAuditNote lbpmAuditNote=lbpmAuditNoteList.get(i);
String base64Str = "";
if (lbpmAuditNote.getFdHandler() != null) {
List<SysAttMain> attMainList = FreemarkerUtils.getPicAttBySignature(lbpmAuditNote.getFdHandler());
if (!ArrayUtil.isEmpty(attMainList) && getSysAttMainService().getInputStream(attMainList.get(0)) != null) {
base64Str = Base64.encode(getSysAttMainService().getInputStream(attMainList.get(0)));
}
}
if ("起草节点".equals(lbpmAuditNote.getFdFactNodeName()) && "drafter_submit".equals(lbpmAuditNote.getFdActionKey())) {
dataMap.put("经办人签名日期", lbpmAuditNote.getFdCreateTime() != null ? DateUtil.convertDateToString(lbpmAuditNote.getFdCreateTime(), "yyyy年MM月dd日") : "");
dataMap.put("经办人签名", base64Str);
} else if ("申请注册师审批".equals(lbpmAuditNote.getFdFactNodeName()) && "handler_pass".equals(lbpmAuditNote.getFdActionKey())) {
zcsqmList.add(base64Str);
dataMap.put("注册执业师签名日期", lbpmAuditNote.getFdCreateTime() != null ? DateUtil.convertDateToString(lbpmAuditNote.getFdCreateTime(), "yyyy年MM月dd日") : "");
} else if ("组织人事部经办人".equals(lbpmAuditNote.getFdFactNodeName()) && "handler_pass".equals(lbpmAuditNote.getFdActionKey())) {
dataMap.put("组织人事部签名日期", lbpmAuditNote.getFdCreateTime() != null ? DateUtil.convertDateToString(lbpmAuditNote.getFdCreateTime(), "yyyy年MM月dd日") : "");
dataMap.put("组织人事部签名", base64Str);
}
}
dataMap.put("申请人列表", zcsqmList);
}
return dataMap;
}
3.创建freemaker导出模板
1.将对应的表保存到word2003中。
2.需要赋值的地方用相应的字符占位,签名或图片要用相应大小的图片占位
3.另存为xml文件,
4.然后将.xml后缀改为.ftl。
5.参数赋值
将刚刚占位的字符和图片改为${}(参数为刚刚java代码中Map中赋值的参数)
5.保存重启测试
2.没有分类直接导出
与有分类的相同但是将按钮换成,
<ui:button text="Word导出" οnclick="downloadDoc()"></ui:button>
并在到导出页面添加方法(指定自己的Id和Type
<script> function downloadDoc() { var url = "/pro/word/proWordDownload.do?method=downloadWord&fdId=${param.fdId}&type=${wordType}"; Com_OpenWindow('${LUI_ContextPath}' + url, '_blank'); } </script>
不用拉起弹框直接请求打印,其余相同