/**
*
* @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. Python中输出格式化的字符串

    在Python中,采用的格式化方式和C语言是一致的,用%实现,举例如下: >>> 'Hello, %s' % 'world' 'Hello, world' >>> ...

  2. BZOJ3252: 攻略

    Description 题目简述:树版[k取方格数]   众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景 ...

  3. ActiveMQ集群应用

    ActiveMQ集群 ActiveMQ具有强大和灵活的集群功能,但在使用的过程中会发现很多的缺点,ActiveMQ的集群方式主要由两种:Master-Slave和Broker Cluster. 1.M ...

  4. 常见bug及解决方案

    1.外边距叠加 一.发生在一个div内 <!DOCTYPE> <html> <head> <meta http-equiv=Content-Type cont ...

  5. 2016huasacm暑假集训训练四 数论_A

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/F 题意:狼捉兔子,兔子躲在n个洞中一个,这n个洞围成一个圈,狼会从第0号洞开始,搜 ...

  6. C++STL -- vector实现

    STL的vector简化实现 本质 vector说到底就是一个动态数组,我们需要做的就是管理动态数组的内存,和元素的增加,删除,移动等. template <typename T> cla ...

  7. python类型转换

    1.数字转字符串 str(42) == "42" 2.字符串转数字 int("42") == 42 3.字符转ascii码 ord("a") ...

  8. 20145220&20145209&20145309信息安全系统设计基础实验报告(2)

    20145220&20145209&20145309信息安全系统设计基础实验报告(2) 实验报告链接: http://www.cnblogs.com/zym0728/p/6083664 ...

  9. Software Solutions CACHE COHERENCE AND THE MESI PROTOCOL

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Software cache cohere ...

  10. Source Insight设置

    Source Insight设置 1.背景色选择     要改变背景色Options->preference->windows background->color设置背景色,设置自定 ...