/**
*
* @param pRun
* @param 20 间距
* @param fontSize 字体大小
* @param bold 是否加粗
* @param underLine 是否下划线
* @param underLineColor 下划线的颜色
* @param underLineStyle 下划线的样式 1
*/
private static void setCommonRunStyle(XWPFRun pRun,int Textposition,int fontSize,boolean bold,boolean underLine,String underLineColor,int underLineStyle){
pRun.setFontSize(fontSize);//设置字体大小
pRun.setFontFamily("Courier"); // 设置使用何种字体
pRun.setTextPosition(Textposition); // 设置上下两行之间的间距
pRun.setBold(bold); // 设置加粗 CTRPr pRpr = null;
if (pRun.getCTR() != null) {
pRpr = pRun.getCTR().getRPr();
if (pRpr == null) {
pRpr = pRun.getCTR().addNewRPr();
}
}
if(underLine){
CTUnderline u = pRpr.isSetU() ? pRpr.getU() : pRpr.addNewU();
u.setVal(STUnderline.Enum.forInt(Math.abs(underLineStyle % 19)));
if (underLineColor != null) {
u.setColor(underLineColor);
}
}
} /****
* word 中添加换行
* @param i i必须要大于0 i为几 就是中间添加几个20的高度
*/
private static void wordHeight(int j,XWPFDocument doc){
for(int i=0;i<j;i++){
XWPFParagraph kongP1= doc.createParagraph();
XWPFRun kongP1Run = kongP1.createRun();
setCommonRunStyle(kongP1Run,100,100,false,false,"666666",1);
kongP1Run.setText(" ");
}
} /**
* 下载计划书word
* @author
* @time
* @description
*/
public static String downloadPlanWord(HttpServletRequest request,HttpServletResponse response){
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
Delegator delegator = (Delegator)request.getAttribute("delegator");
GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
Map<String, Object> outResult = ServiceUtil.returnSuccess();
String startTime = request.getParameter("startTime");
String endTime = request.getParameter("endTime");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
XWPFDocument doc = new XWPFDocument();
try {
//根据农户进行计划查询的分组 未执行的
List<EntityCondition> Conds = FastList.newInstance();
Conds.add(EntityCondition.makeCondition("executeStatusId", EntityOperator.EQUALS,"PPLECT_UNEXECUTED"));
if(UtilValidate.isNotEmpty(startTime)){
Conds.add(EntityCondition.makeCondition("planStartTime",EntityOperator.GREATER_THAN_EQUAL_TO,Timestamp.valueOf(startTime+" 00:00:00")));
}
if(UtilValidate.isNotEmpty(endTime)){
Conds.add(EntityCondition.makeCondition("planStartTime",EntityOperator.LESS_THAN_EQUAL_TO,Timestamp.valueOf(endTime+" 00:00:00")));
}
List<GenericValue> planList = delegator.findList("MaterialProductionPlanInfo",
EntityCondition.makeCondition(Conds),null, null, null, false);
if(UtilValidate.isEmpty(planList)){
XWPFParagraph noFarmer = doc.createParagraph();
noFarmer.setAlignment(ParagraphAlignment.CENTER);
noFarmer.setVerticalAlignment(TextAlignment.TOP);
XWPFRun noFarmerRun = noFarmer.createRun();
setCommonRunStyle(noFarmerRun,20,20,true,false,"666666",1);
noFarmerRun.setText("没有农户存在种植计划");
response.reset();
String fileName = "种植计划书.doc";
response.setContentType("application/x-msdownloadoctet-stream;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename=\"" + URLEncoder.encode(fileName, "UTF-8"));
OutputStream out = response.getOutputStream();
doc.write(out);
out.flush();
doc.write(out);
out.close();
return "error";
}
Map<String,List<GenericValue>> farmerMap = FastMap.newInstance();
for(GenericValue plan:planList){
if(farmerMap.containsKey(plan.getString("farmerId"))){
farmerMap.get(plan.getString("farmerId")).add(plan);
}else{
List<GenericValue> planEntityList = FastList.newInstance();
planEntityList.add(plan);
farmerMap.put(plan.getString("farmerId"),planEntityList);
}
}
int i =0;
XWPFParagraph titleP = null;
GenericValue farmerEntity = null;
for(String key : farmerMap.keySet()){
farmerEntity = delegator.findOne("Farmer", false, UtilMisc.toMap("farmerId", key));
planList = farmerMap.get(key);
titleP = doc.createParagraph();
if(i>0){
titleP.setPageBreak(true);
}
i++;
titleP.setAlignment(ParagraphAlignment.CENTER);// 设置字体对齐方式
XWPFRun titlePRun = titleP.createRun(); // 第一页要使用p1所定义的属性
setCommonRunStyle(titlePRun,40,20,true,false,"666666",1);
titlePRun.setText("种植计划下达通知书");
// 农户
XWPFParagraph farmerP = doc.createParagraph();
XWPFRun farmerRunLabel = farmerP.createRun();// 第一页要使用p1所定义的属性
setCommonRunStyle(farmerRunLabel,20,16,false,false,"666666",1);
farmerRunLabel.setText("农户:");
XWPFRun farmerRun = farmerP.createRun();// 第一页要使用p1所定义的属性
setCommonRunStyle(farmerRun,20,16,false,true,"666666",1);
farmerRun.setText(farmerEntity.getString("farmerName"));
//计划数目
XWPFParagraph sizeP = doc.createParagraph();
XWPFRun sizeRunLabel1 = sizeP.createRun();
setCommonRunStyle(sizeRunLabel1,20,16,false,false,"666666",1);
sizeRunLabel1.setText(" 根据农场生产计划总体安排,对您提出的");
XWPFRun sizeRunValue = sizeP.createRun();
setCommonRunStyle(sizeRunValue,20,16,false,true,"666666",1);
sizeRunValue.setText(String.valueOf(planList.size()));
XWPFRun sizeRunLabel2 = sizeP.createRun();
setCommonRunStyle(sizeRunLabel2,20,16,false,false,"666666",1);
sizeRunLabel2.setText("座棚种植请求,现通知如下:");
//空行
wordHeight(1,doc);
//种植计划
int planIndex=0;
for(GenericValue plan:planList){
planIndex ++ ;
XWPFParagraph planP = doc.createParagraph();
planP.setVerticalAlignment(TextAlignment.TOP);
XWPFRun farmFieldNameRun = planP.createRun();
setCommonRunStyle(farmFieldNameRun,20,16,false,true,"666666",1);
farmFieldNameRun.setText(plan.getString("farmFieldName")); XWPFRun planRunLabel1 = planP.createRun();
setCommonRunStyle(planRunLabel1,20,16,false,false,"666666",1);
planRunLabel1.setText("棚,种植品种"); XWPFRun materialNameRun = planP.createRun();
setCommonRunStyle(materialNameRun,20,16,false,true,"666666",1);
materialNameRun.setText(plan.getString("materialName")); XWPFRun planRunLabel2 = planP.createRun();
setCommonRunStyle(planRunLabel2,20,16,false,false,"666666",1);
planRunLabel2.setText(",种植时间"); String planStartTimeStr = sdf.format(new Date(plan.getTimestamp("planStartTime").getTime()));
XWPFRun planStartTimeRun = planP.createRun();
setCommonRunStyle(planStartTimeRun,20,16,false,true,"666666",1);
planStartTimeRun.setText(planStartTimeStr);
if(planIndex==planList.size()){
wordHeight(4,doc);
}
}
//提示
XWPFParagraph tipP = doc.createParagraph();
tipP.setAlignment(ParagraphAlignment.CENTER);
tipP.setVerticalAlignment(TextAlignment.TOP);
XWPFRun tipPRun = tipP.createRun();
setCommonRunStyle(tipPRun,120,14,false,false,"666666",1);
tipPRun.setText("请务必按照通知下达的计划种植,否则公司不负责收购。");
//农户
XWPFParagraph farmerSignP = doc.createParagraph();
XWPFRun farmerSignPRun = farmerSignP.createRun();
setCommonRunStyle(farmerSignPRun,30,16,false,false,"666666",1);
farmerSignPRun.setText("农户:");
//技术员
XWPFParagraph technicianP = doc.createParagraph();
XWPFRun technicianPRun = technicianP.createRun();
setCommonRunStyle(technicianPRun,30,16,false,false,"666666",1);
technicianPRun.setText("技术员:");
//负责人
XWPFParagraph chargerP = doc.createParagraph();
XWPFRun chargerPRun = chargerP.createRun();
setCommonRunStyle(chargerPRun,30,16,false,false,"666666",1);
chargerPRun.setText("负责人:");
//通知送达时间
XWPFParagraph deliveryTimeP = doc.createParagraph();
XWPFRun deliveryTimePRun = deliveryTimeP.createRun();
setCommonRunStyle(deliveryTimePRun,30,16,false,false,"666666",1);
deliveryTimePRun.setText("通知送达时间: 年 月 日");
//苏星生态农业生产科
XWPFParagraph suxP = doc.createParagraph();
suxP.setAlignment(ParagraphAlignment.RIGHT);
XWPFRun suxPRun = suxP.createRun();
setCommonRunStyle(suxPRun,30,16,false,false,"666666",1);
suxPRun.setText("苏星生态农业生产科");
}
response.reset();
String fileName = "种植计划书.doc";
response.setContentType("application/x-msdownloadoctet-stream;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename=\"" + URLEncoder.encode(fileName, "UTF-8"));
OutputStream out = response.getOutputStream();
doc.write(out);
out.flush();
doc.write(out);
out.close();
} catch (GenericEntityException e) {
// TODO Auto-generated catch block
Debug.logError(e, "查询农户种植计划异常" + e.toString(), module);
CommonEvents.writeResultToResponse(ServiceUtil.returnError("查询农户种植计划异常"), response);
return "error";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}

word自定义格式 并下载的更多相关文章

  1. Excel 单元格自定义格式技巧总结

    第一部分 Excel 中的单元格格式是一个最基本但是又很高级的技能,说它基本是因为我们几乎天天都会用到它,会用它来设置一些简单的格式,比如日期,文本等等:高级是因为利用 Excel 单元格的自定义格式 ...

  2. WORD自定义宏

    自定义快捷键 折叠所有标题 Word选项—自定义功能区—自定义键盘—不在功能区内的命令—ColllapseAllHeadings 展开所有标题 Word选项—自定义功能区—自定义键盘—不在功能区内的命 ...

  3. 代码中设置excel自定义格式为[红色]的处理方法

    有时候,excel的自定义格式设置时 ,会遇到需要设置为¥#,##0;[红色]¥-#,##0的格式. 其中会带一个颜色标记,但是如果这样的一句代码,放在英文版的Office里面,就失效了,因为英文版应 ...

  4. logback自定义格式转换器

    创建自定义格式转换符有两步. 首先,必须继承ClassicConverter类.ClassicConverter对象负责从ILoggingEvent 提取信息,并产生一个字符串.例如,LoggerCo ...

  5. 去掉word冗余格式 java正则表达式

    word转换html时,会留下很多格式,有些格式并不是我们所需要的,然而这些格式比真正的文章内容还要多,严重影响页面的加载速度,因此就需要找个一个好的解决方案把这些多余的格式个去掉.网上有很多去除wo ...

  6. Objective-c 多线程操作 自定义NSOperation 模拟下载

    写在前面 使用多线程下载图片,使用内存缓存和磁盘缓存. 这里只为理解NSOperation及其派生类 真要应用到APP中 请下载成熟的第三方库 效果 下载多张图片时可控制线程并发数 分析 自定义NSO ...

  7. csv格式订单下载,完成后伴随邮件通知下载

    前言 功能开发中会遇到大量订单下载,而服务器的请求响应时间又配置的很短,导致下载时候请求超时. 这篇文章主要思路:异步查询数据,生成csv文件,放入email中并发送给用户.(异步部分本文不做介绍,配 ...

  8. Word自定义多级列表样式

    Word自定义多级列表样式: 1. 2. 3.取个名字 在这里鼠标移上时显示 : 4. 5. 定义完成,即可使用:

  9. 用 Lua 控制 MIDI 合成器来播放自定义格式乐谱

    用 Lua 控制 MIDI 合成器来播放自定义格式乐谱 作者: FreeBlues 最新: https://www.cnblogs.com/freeblues/p/9936844.html 说明: 本 ...

随机推荐

  1. addview的使用

    之前,使用addview(控件1)的时候 之前是需要给控件1添加一个位置设定,比如是设定在右侧 使用了addrule 但是我想到的是,如果是给一个view 的 后面延长,把该控件放在上面呢?

  2. language level in Intellij IDEA

    The Language level setting sets which features the code assistance in the editor should support. For ...

  3. 在Lingo中输入矩阵(通过Excel)

    举例说明:我要将'C:\Users\Lenovo\Desktop\lingodata.xlsx'里的数据导入lingo1.左键拖动选中'C:\Users\Lenovo\Desktop\lingodat ...

  4. php获取html纯文本,解决编辑器手动键入空格造成的无意义空白字符(空值问题)

    在项目中,我们常常需要用到一些验证,不管是前台还是后台的,上传的问题时,需要内容不为空,但可视化编辑器的介入让手动敲入空格跳出了常规的检测.空格是一种排版的手段,但毫无内容只有空格就显得没有意义了,今 ...

  5. easyUI中的form表单

    首先创建form表单,并在form表单上创建id便于执行表单验证 <form id="form1"action="" method="post& ...

  6. java Properties 配置信息类

    Properties(配置信息类):主要用于生产配置文件和读取配置文件信息. ----> 是一个集合类 继承HashTable 存值是以键-值的方式. package com.beiwo.io; ...

  7. workspace路径有中文情况会报java.net.MalformedURLException: unknown protocol: d错误

    原因及描述:java读取xml文件时如果出现中文字符就会出现这类错误 解决方法:   1.将中文路径改为英文路径 2.读取file时"file:///d:/" 而不是"d ...

  8. Javascript初学篇章_1(概念/数据类型)

    Javascript是一门脚本语言,主要由浏览器来执行.它可以说是页面的灵魂,让页面活过来.与之前学的HTML5+CSS样式的不同之处就在于,JS能让静态网页成为一个动态网页,实现与用户的互动. Ja ...

  9. asp.net identity 3.0.0 在MVC下的基本使用 序言

    本人也尚在学习使用之中,错误之处请大家指正. 开发环境:vs2015 UP1   项目环境:asp.net 4.6.1   模板为:asp.net 5 模板     identity版本为:asp.n ...

  10. Ubuntu使用阿里云软件源

    如果在安装Ubuntu时,选择的地区为美国,建议更新为阿里云或国内 软件源 sudo sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt ...