/**
*
* @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. 转载:持续集成之解决jenkins内存溢出问题

    在jenkins master-slave配置中,总是出现内存溢出问题,更换了机器设备仍然跑不起来: 问题如下: Status Code: 500    Exception: org.apache.c ...

  2. Python中实现从目录中过滤出指定文件类型的文件

    摘自:http://www.jb51.net/article/60641.htm #!/usr/bin/env python import glob import os os.chdir(“./”) ...

  3. Linux CentOS下安装Oracle

    1 .在安装oracle之前首先安装以下组件包,直接输入下列语句安装. yum install binutils* -y yum install compat-lib* -y yum install ...

  4. GridView的七种数据绑定列的类型

    1.BoundField 用于显示普通文本,是默认的数据绑定列的类型,一般自动生成的列就是该类型,需要注意是DataFormatString属性,该属性可以设置显示的格式,常见格式有:{0:C} 设置 ...

  5. UVA 10791 Minimum Sum LCM(分解质因数)

    最大公倍数的最小和 题意: 给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 那么找出一个序列,使他们的和最小. 分析: 一系列数字a1,a2,a3 ...

  6. css 注意点

    HTML css 一.整体布局 1.创建一个html标签 2.创建三个div标签(分别是网页的头部,中间,和底部三部分) 3.一般都用class选择器 4.用css给body标签加个 margin:0 ...

  7. 01 LabVIEW的类中各个Scope的范围

    范例地址: D:\Program Files (x86)\National Instruments\LabVIEW 2015\examples\Object-Oriented Programming\ ...

  8. Android课程---优化ListView列表视图(2)

    layout_simple.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  9. Visual Studio 2010编译时总是提示"调用目标发生了异常"的解决

    现象: 无论建立的是Win32 Console的解决方案,还是MFC的解决方案,重新打开Visual Studio 2010之后,编译时总是提示“调用的目标发生了异常” 解决: 1. 关闭Visual ...

  10. windows计划任务+批处理文件实现oracle数据库的定时备份与恢复

    1.  备份: PS:2014-1-15 如果导出的dmp数据文件不大的话,就直接每天导出好了,不要只保存七天的数据.然后顶起通过winrar对文件进行打包,我发现dmp文件的压缩包还是很高的. 那么 ...