相关一部分java文件和jar包

pom文件

com.aspose

aspose-words

18.2

word模板 其中的内容要在设置在表格里面

js导出方法

functionf_export(){var rowsdata =gridManager.getSelectedRow();if (!rowsdata) {

$.ligerDialog.alert('请先选择一行!');return;

}

manwait= $.ligerDialog.waitting("正在导出,请稍候...");var statDate =rowsdata.statDate;

$.ajax({

type :"POST",

url:'${ctx}/dp/schedulingLogQuery!exportView.action',

data:$("#form").serializeArray(),

dataType :"json",

cache:false,

success : f_success

});

}

action代码

public voidexportView(){

ISchedullingFetchMap fetchmap= (ISchedullingFetchMap) this.getMap();

fetchmap.generation(modelId,TimeUtil.parseDate(statDate), shiftId);

Map map = new HashMap<>();

map.put("status", 200);

JSONObject jsonObject=JSONObject.fromObject(map);

ResponseUtil.print(jsonObject.toString());

}

map代码 生成words和pdf

public voidgeneration(Long modelId, Date parseDate, Long shiftId) {

List> fetchList= this.findFetchs(modelId, parseDate, shiftId);

Map varValues = new HashMap();

Model model= (Model) this.getPersistQuery().findById(Model.class, modelId);

varValues.put("name", model.getModelName());

varValues.put("dateStr", parseDate);

List> fetchs = new ArrayList<>();//varValues.put("fetchs", fetchList);

for (Mapmap : fetchList) {

Map map2 = new HashMap();

String content= map.get("demo").toString();

map2.put("demo", content);

map2.put("fetchName", map.get("fetchName").toString());

fetchs.add(map2);

}

varValues.put("fetchs", fetchs);//根据msword报表模板生成msword

String tmpFilename = ServletActionContext.getServletContext().getRealPath("/template/***.docx");//模板文件//要导出文件

String workFilename = ServletActionContext.getServletContext().getRealPath("/reportWorkSpace/**********.docx");

Report report= newReport();

report.tmpFilename=tmpFilename;

report.workFilename=workFilename;

report.varValues=varValues;

report.transformDOCX();

}

report.transformDOCX();实现根据模板转成word并转成pdf,html,xps,png等,该java文件可在上方连接获取

public voidtransformDOCX() {//载入模板文件

msword.report.Operate.load(this);//解析

msword.report.Operate.execute(this);//再替换没有匹配的${}为空字符

msword.report.Operate.scavengeSuperfluous(this);//保存工作文件

msword.report.Operate.save(this);//转换为pdf文件

aspose.Operate.convertasPdf(this);//转换为html文件//aspose.Operate.convertasHtml(this);//转换为xps文件//aspose.Operate.convertasXps(this);//转换为png文件//aspose.Operate.convertasPng(this);

}

分别下载word文件和pdf文件

//下载word

functionf_success(data){if (data.status == 200) {//ligerUi提示

var manager =$.ligerDialog.tip({

title :'提示',

content :'操作成功!'});

manwait.close();

setTimeout(function() {

manager.close();

},3000);

document.getElementById("belowFrame").contentWindow.location.href="${pageContext.request.contextPath}//reportWorkSpace/********.docx";

setTimeout(function() {

parent.window.frames[thisTabId].f_closeWindow();

},100);

}else{

$.ligerDialog.closeWaitting();

$.ligerDialog.error(data.message);

}

}

//下载pdf

functionf_success(data){if (data.status == 200) {//ligetUi提示

var manager =$.ligerDialog.tip({

title :'提示',

content :'操作成功!'});

manwait.close();//定时关闭提示

setTimeout(function() {

manager.close();

},3000);

window.location.href='${ctx}/dp/schedulingLogQuery!exportPdfView.action';

setTimeout(function() {

parent.window.frames[thisTabId].f_closeWindow();

},100);

}else{

$.ligerDialog.closeWaitting();

$.ligerDialog.error(data.message);

}

}

下载pdf后台代码

public voidexportPdfView(){

HttpServletRequest request =ServletActionContext.getRequest();String TEMPLATE_FILE= "/reportWorkSpace/*******.pdf";

String templatePath1=BaseService.getInstance().getRealPath(TEMPLATE_FILE);

File file=newFile(templatePath1);

String fileName=file.getName();String agent=(String)request.getHeader("USER-AGENT"); //判断浏览器类型

try{if(agent!=null && agent.indexOf("Fireforx")!=-1) {

fileName= new String(fileName.getBytes("UTF-8"), "iso-8859-1"); //UTF-8编码,防止输出文件名乱码

}else{

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

}

}catch(Exception e) {

e.printStackTrace();

}

OutputStream os=null;

HttpServletResponse response=ServletActionContext.getResponse();

response.reset();

response.setCharacterEncoding("utf-8");

response.setContentType("application/pdf"); //pdf格式

response.setHeader("Content-Disposition", "attachment; filename=" +fileName);try{

BufferedInputStream bis=new BufferedInputStream(newFileInputStream(file));byte[] b=new byte[bis.available()+1000];int i=0;

os= response.getOutputStream(); //直接下载导出

while((i=bis.read(b))!=-1) {

os.write(b,0, i);

}

os.flush();

os.close();

}catch(IOException e) {

e.printStackTrace();

}finally{if(os!=null) {try{

os.close();

}catch(IOException e) {

e.printStackTrace();

}

}

}

}

java根据word模板导出_java根据模板生成,导出word和pdf(aspose.words实现word转换pdf)...相关推荐

  1. java调用word模板文件_Java使用模板导出word文档

    Java使用模板导出word文档 需要导入freemark的jar包 使用word模板,在需要填值的地方使用字符串代替,是因为word转换为xml文件时查找不到要填入内容的位置.尽量不要在写字符串的时 ...

  2. java生成word 框勾_Java 使用模板生成 Word 文件---基于 Freemarker 模板框架

    Java项目引入 Freemarker 插件自行完成. 步骤如下: 1.编写 Word 模板,并将模板中要用代码动态生成数据用 Freemarker 变量取代,即${变量名},如${username} ...

  3. java导出生成word文档_java使用freemarker 生成word文档

    最近需要做一个导出word的功能, 在网上搜了下, 有用POI,JXL,iText等jar生成一个word文件然后将数据写到该文件中,API非常繁琐而且拼出来的样式也不美观,于是选择了另一种方式--- ...

  4. java重命名sheet失败_java jxl excel 数据导出 重新命名无效的工作表名称 | 学步园...

    今天在java中使用jxl导出数据到excel工作表的时候,无论是在线直接打开还是保存到本地再打开,都会提示下面的错误信息: "Excel在'excel.xls'中发现不可读取的内容.是否恢 ...

  5. java实现mysql的导入导出_Java实现mysql导入导出Excel

    [实例简介] Java实现mysql导入Excel,Excel数据导入mysql,可以设置excel的样式, [实例截图] [核心代码] 088e0021-a7ee-4558-9fa9-257939e ...

  6. java基本数据类型的标识符_java基础(一)-标识符、变量、基本数据类型及转换、运算符及表达式...

    一.标识符 二.关键字 三.JAVA基础数据类型 3.1.常量 3.2.变量 从本质上来讲,变量其实是内存里面的一小块区域,一个程序在运行的时候,实际上这个程序是位于内存里面,然后才开始运行.一个.e ...

  7. java随机安排座位表程序_java – 为长凳生成随机座位表的最有效算法?

    我正在为一位教师的家庭成员编写应用程序.她要求一个应用程序,允许她进入一群孩子,设定他们的惯用手,设置他们不能坐在旁边的人,指定每个工作台有多少个座位,然后为孩子们生成一个随机的布局,这样就没有了 – ...

  8. JAVA怎么才能强制换行_Java利用POI生成Excel强制换行(转载)

    使用POI创建一个简单的 myXls.xls 文件 常用的包为 org.apache.poi.hssf.usermodel.*; 例子: import java.io.*; import org.ap ...

  9. java产生随机英文名_Java之随机生成用户数据

    我们在进行单元测试或者运行一些需要虚拟用户的数据的模块的时候,总觉得手动添加这些数据很麻烦,特别是在遇到需要添加大量用户数据的时候,为了防止浪费大量时间,可以使用下面的几个方法来获得随机用户. 先假设 ...

最新文章

  1. openstack(Queens) neutron-l3-agent 代码解析1(从命令行启动到同步plugin数据)
  2. ASP.NET-------字符串和字节数组转换
  3. 网易云信助力长沙银行打造远程视频银行 | 字母点评数字化先锋案例
  4. 关于DELL服务器如果采购散件,进行服务器升级的相关说明
  5. [CodeForces - 950D]A Leapfrog in the Array(思维)
  6. 开始gentoo之旅
  7. django-celery beat报错 error pid
  8. python基础-字符串(6)
  9. python中re是什么库_Python正则表达式和re库知识点总结
  10. python实现一款编译型语言_Java,Python谁是编译型语言,谁是解释型语
  11. 国二java好过还是office好过,计算机二级考哪一个科目比较容易过,Ms office 较为简单实用...
  12. 单元刚度矩阵 C++
  13. T9社区注册流程记录(笔记)
  14. 如何避免成为一个油腻的中年猥琐男
  15. linux格式化硬盘怎么那么慢,linux系统中怎么格式化硬盘
  16. 战地5未能达到服务器带宽,《战地5》游戏bug汇总以及解决方案介绍
  17. Spring关于@required注解
  18. 数据结构与算法(二叉树)
  19. OSChina 周日乱弹 ——我是胖娜丽莎
  20. 配置OpenCV产生flann\logger.h(66): error C4996: 'fopen': This function or variable may be unsafe问题

热门文章

  1. 深度学习及并行化实现概述
  2. python 两点曲线_Python自学教程| 3万字详解每个重要知识点(内附视频)
  3. oracle付款汇兑损益怎么产生,月末汇兑损益怎么算调整分录如何做
  4. 在阿里我是如何当面试官的
  5. 聚合支付码是什么意思及它产生的背景
  6. [论文速度] 同时解决成像时,曝光不足和曝光过度问题:Deep Reciprocating HDR Transformation
  7. 哔哩哔哩2020校园招聘算法笔试卷(二)
  8. python水印检测_使用Python检测照片中的特定水印(无SciPy)
  9. 图像修复(Image Restoration)
  10. 最长递增子序列 O(NlogN)算法