当前位置: 首页 > news >正文

义乌做网站多少钱产品推广渠道

义乌做网站多少钱,产品推广渠道,厦门学网站设计,大施品牌策划公司续上一期的更新内容 ,导出的是单张图片,直接在路径的src 里面填写对应的占位符,就可以了,随着需求的变化,那么今天我们继续往下写一个循环导出多张图片到word里面。 使用FreeMarker导出word文档(支持导出单张图片) …

续上一期的更新内容  ,导出的是单张图片,直接在路径的src  里面填写对应的占位符,就可以了,随着需求的变化,那么今天我们继续往下写一个循环导出多张图片到word里面。

使用FreeMarker导出word文档(支持导出单张图片)

首先我们需要进行在word 里面把对应的模版设置好。

设置好点击另存为,目前我用的html 格式的,网上也有很多xml  形式的,每种写法还不一样

接着我们用记事本进行打开,第一步一定要先修改编码格式为utf-8的

然后我们将html 中head中的标签全部,如果编码不修改,head标签不删除,将来导出的时候就是乱码,这个坑是很深的,排查了好长时间才解决。

这些都修改好后,我们点击另存为将这个模版改成后缀为ftl形式的

接下来我们就开始编写代码

	@Overridepublic void exporttdYsdWord(HttpServletRequest request,HttpServletResponse response, String objId, String gllx) {List<Map<String, String>> list = null;List<Map<String, String>> list3 = null;List<Map<String, String>> list5 = null;String ysdName = "";String ysdSql = "";String zpSql = "";String sdsgfa = "";String ysgjjd = "";String sdsgfaEname = "";if ("0".equals(gllx)) {sdsgfa = "sdsgfa";ysgjjd = "ysgjjd";sdsgfaEname = "sczbjys_sczbjys_sdsgfa";ysdName = "中间环节验收报告";ysdSql = "select t.gcmc,t.jgdw,t.jgdwfzr,t.jgdwfzrdh,"+ "t.tdsgdw,t.tdsgdwlxr,t.tdsgdwlxrdh,to_char(t.sqyssj,'yyyy-MM-dd') sqyssj,"+ "t.czwt,  (select a.username from gw_yhgl_user a where a.id = t.yxbzrm) yxbzrm, (select h.value  from gw_limit_enums h  where h.enumName like '%sczbjys_sczbjys_yxbz%' and h.key = t.yxbz) yxbz,(select t.value from   gw_limit_enums t   where   t.enumName like '%sczbjys_sczbjys_ysgjjd%'  and t.key=ysgjjd)  ysgjjd from GW_SCZBJYS_ZLC t where t.OBJ_ID = ?";}list = this.hibernateDao.queryForListWithSql(ysdSql,new String[]{objId});Map<String, String> map0 = new HashMap<String, String>();Map<String, Object> map = new HashMap<String, Object>();StringBuilder sb = new StringBuilder();String aa="";zpSql="select   t.ipath ,t.dpt from   gw_pig_address_rw t   where  t.taskid=?   and t.ipath is not   null  and t.dpt='问题照片'  and t.dpt  is not null   and t.ipath   not  like '%dat%'" ;list3 = this.hibernateDao.queryForListWithSql(zpSql,new String[]{objId});String 	zpSqla="select   t.ipath ,t.dpt from   gw_pig_address_rw t   where  t.taskid=?   and t.ipath is not   null   and t.dpt  is not null   and t.ipath   not  like '%dat%'" ;list5 = this.hibernateDao.queryForListWithSql(zpSqla,new String[]{objId});if(list3.size()>0){for (Map<String, String> stringObjectMap : list3) {if (stringObjectMap.get("DPT").equals("问题照片")) {
//		                	map.put("PSZP", "" + PlatformConfigUtil.getString("TASK_PIC_ADDRESS") + stringObjectMap.get("IPATH"));
//		                     aa= String.valueOf(sb.append(PlatformConfigUtil.getString("TASK_PIC_ADDRESS")+ stringObjectMap.get("IPATH")).append(","));
//		                	 aa= String.valueOf(sb.append("  <img width=249  height=273\"  src=\""+PlatformConfigUtil.getString("TASK_PIC_ADDRESS") + stringObjectMap.get("IPATH")).append(">").append(","));aa= String.valueOf(sb.append("<img width=\"249\"  height=\"273\" src=\""+PlatformConfigUtil.getString("TASK_PIC_ADDRESS") + stringObjectMap.get("IPATH")+"\">").append(","));}}}else{for (Map<String, String> stringObjectMap : list5) {if (!stringObjectMap.get("DPT").equals("问题照片")) {
//		                	map.put("PSZP", "" + PlatformConfigUtil.getString("TASK_PIC_ADDRESS") + stringObjectMap.get("IPATH"));
//		                     aa= String.valueOf(sb.append(PlatformConfigUtil.getString("TASK_PIC_ADDRESS")+ stringObjectMap.get("IPATH")).append(","));String   hh="<img width=\"249\"  height=\"273\"  src=\"http://192.168.200.86:18080/XSGL/2023-07-27/20230802155008.jpg\",<img width=\"249\"  height=\"273\"  src=\"http://192.168.200.86:18080/XSGL/2023-07-27/20230802154952.jpg\"";aa= String.valueOf(sb.append("<img width=\"249\"  height=\"273\" src=\""+PlatformConfigUtil.getString("TASK_PIC_ADDRESS") + stringObjectMap.get("IPATH")+"\">").append(","));}}}if(aa.length()>0){String a1 = aa.substring(0, aa.length() - 1);map.put("PSZP", a1);}else{if(aa.length()>0){String a1 = aa.substring(0, aa.length() - 1);map.put("PSZP", a1);}else{map.put("PSZP", "");}}if (!Tool.isEmptyList(list)) {map0 = list.get(0);if (Tool.isEmptyStr(map0.get("gcmc"))) {map.put("GCMC", "");} else {map.put("GCMC", map0.get("gcmc"));}if (Tool.isEmptyStr(map0.get("jgdw"))) {map.put("JGDW", "");} else {map.put("JGDW",getEnumsValueFromEnumDB("sczbjys_sczbjys_jgdw",map0.get("jgdw")));}if (Tool.isEmptyStr(map0.get("tdsgdw"))) {map.put("TDSGDW", "");} else {map.put("TDSGDW", map0.get("tdsgdw"));}if (Tool.isEmptyStr(map0.get("tdsgdwlxr"))) {map.put("TDSGDWLXR", "");} else {map.put("TDSGDWLXR", map0.get("tdsgdwlxr"));}if (Tool.isEmptyStr(map0.get("tdsgdwlxrdh"))) {map.put("TDSGDWLXRDH", "");} else {map.put("TDSGDWLXRDH", map0.get("tdsgdwlxrdh"));}if (Tool.isEmptyStr(map0.get("yxbz"))) {map.put("YXBZ", "");} else {map.put("YXBZ", map0.get("yxbz"));}if (Tool.isEmptyStr(map0.get("yxbzrm"))) {map.put("YXBZRM", "");} else {map.put("YXBZRM", map0.get("yxbzrm"));}if (Tool.isEmptyStr(map0.get("ysgjjd"))) {map.put("YSGJJD", "");} else {map.put("YSGJJD", map0.get("ysgjjd"));}if (Tool.isEmptyStr(map0.get("sqyssj"))) {map.put("SQYSSJ", "");} else {SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");String string = map0.get("sqyssj"); Date parse = null;try {parse = simpleDateFormat.parse(string);} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}String format = simpleDateFormat.format(parse);StringBuilder myName = new StringBuilder(format);myName.setCharAt(4, '年');myName.setCharAt(7, '月');myName.append("日");System.out.println(myName);
//  时间变成 年月日形式map.put("SQYSSJ", myName.toString());}if (Tool.isEmptyStr(map0.get("czwt"))) {map.put("CZWT", "");} else {map.put("CZWT", map0.get("czwt"));}map.put("SJDW", "设计单位");map.put("JLDW", "监理");map.put("BD", "121");map.put("SDJG", "结构好");map.put("CD", "长度1");map.put("JCJ", "井口1");String   hh="<img width=\"249\"  height=\"273\"  src=\"http://192.168.200.86:18080/XSGL/2023-07-27/20230802155008.jpg\",<img width=\"249\"  height=\"273\"  src=\"http://192.168.200.86:18080/XSGL/2023-07-27/20230802154952.jpg\"";map.put("TFT", "");
//			map.put("PSZP", hh);
//			map.put("YSGJJD", "飒飒");} else {map.put("SJDW", "");map.put("JLDW", "");map.put("BD", "");map.put("SDJG", "");map.put("CD", "");map.put("JCJ", "");map.put("TFT", "");}try {WordUtils.exportWorde(request, response, map, "scbzjystd.ftl",ysdName);} catch (IOException e) {// TODO Auto-generated catch block
//			e.printStackTrace();}}
}

 

图片的格式高宽度提前在代码里面设置好,然后我们在模版里面用一个占位符来进行替代就可以了。

 设置下载格式

	public static void exportWorde(HttpServletRequest request,HttpServletResponse response, Map<String, Object> map,String templateName, String fileName)  throws IOException {String pathString = request.getSession().getServletContext().getRealPath("/WEB-INF/templete/");logger.info("获取到的模板路径是:templetePath------->" + pathString);configuration.setDirectoryForTemplateLoading(new File(pathString));Template freemarkerTemplate = configuration.getTemplate(templateName);File file = null;InputStream fin = null;ServletOutputStream out = null;try {// 调用工具类的createDoc方法生成Word文档file = createDoce(map,freemarkerTemplate);fin = new FileInputStream(file);response.setCharacterEncoding("utf-8");response.setContentType("application/msword");// 设置浏览器以下载的方式处理该文件名fileName = fileName + DateUtil.currentDateToString() + ".doc";response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));out = response.getOutputStream();byte[] buffer = new byte[512];  // 缓冲区int bytesToRead = -1;// 通过循环将读入的Word文件的内容输出到浏览器中while((bytesToRead = fin.read(buffer)) != -1) {out.write(buffer, 0, bytesToRead);}} finally {if(fin != null) fin.close();if(out != null) out.close();if(file != null) file.delete(); // 删除临时文件}}

设置编码:

    private static File createDoce(Map<String, Object> dataMap, Template template) {String name =  ".doc";File f = new File(name);Template t = template;try {// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");t.process(dataMap, w);w.close();} catch (Exception ex) {ex.printStackTrace();throw new RuntimeException(ex);}return f;}

 导出效果

若本文对你有所帮助,请一键三连,说不定后期工作中就用到了。


文章转载自:
http://villeinage.pwrb.cn
http://fishwoman.pwrb.cn
http://incompleteline.pwrb.cn
http://engulf.pwrb.cn
http://carriage.pwrb.cn
http://interphone.pwrb.cn
http://flitch.pwrb.cn
http://lavishment.pwrb.cn
http://needlebook.pwrb.cn
http://epaulement.pwrb.cn
http://actium.pwrb.cn
http://foresail.pwrb.cn
http://detick.pwrb.cn
http://scarfpin.pwrb.cn
http://spadework.pwrb.cn
http://bodiless.pwrb.cn
http://icelandic.pwrb.cn
http://zecchino.pwrb.cn
http://stupor.pwrb.cn
http://electrometry.pwrb.cn
http://ccco.pwrb.cn
http://latticeleaf.pwrb.cn
http://scanning.pwrb.cn
http://eccentricity.pwrb.cn
http://sumac.pwrb.cn
http://dishful.pwrb.cn
http://antihuman.pwrb.cn
http://caliphate.pwrb.cn
http://tourane.pwrb.cn
http://chacma.pwrb.cn
http://outsung.pwrb.cn
http://chemosynthesis.pwrb.cn
http://vitreum.pwrb.cn
http://anthropogeny.pwrb.cn
http://casino.pwrb.cn
http://aorta.pwrb.cn
http://philomena.pwrb.cn
http://cornball.pwrb.cn
http://codification.pwrb.cn
http://cocklebur.pwrb.cn
http://dilutedly.pwrb.cn
http://panopticon.pwrb.cn
http://drew.pwrb.cn
http://missy.pwrb.cn
http://thallous.pwrb.cn
http://weigela.pwrb.cn
http://dek.pwrb.cn
http://mesomorphous.pwrb.cn
http://devil.pwrb.cn
http://solunar.pwrb.cn
http://tetraspore.pwrb.cn
http://semite.pwrb.cn
http://mayon.pwrb.cn
http://partisan.pwrb.cn
http://hypoglobulia.pwrb.cn
http://burgrave.pwrb.cn
http://curare.pwrb.cn
http://poltroon.pwrb.cn
http://chillout.pwrb.cn
http://gamma.pwrb.cn
http://enfeoffment.pwrb.cn
http://immodestly.pwrb.cn
http://peaceful.pwrb.cn
http://wyomingite.pwrb.cn
http://misprint.pwrb.cn
http://guidance.pwrb.cn
http://rattail.pwrb.cn
http://hydrotherapeutic.pwrb.cn
http://asa.pwrb.cn
http://priming.pwrb.cn
http://chisel.pwrb.cn
http://guardship.pwrb.cn
http://nastalik.pwrb.cn
http://dogfight.pwrb.cn
http://placard.pwrb.cn
http://costar.pwrb.cn
http://lunge.pwrb.cn
http://parabolic.pwrb.cn
http://liquidise.pwrb.cn
http://napper.pwrb.cn
http://anywise.pwrb.cn
http://gilolo.pwrb.cn
http://cacomagician.pwrb.cn
http://osteologic.pwrb.cn
http://homomorphous.pwrb.cn
http://racy.pwrb.cn
http://cymling.pwrb.cn
http://adullamite.pwrb.cn
http://subarea.pwrb.cn
http://stone.pwrb.cn
http://fatstock.pwrb.cn
http://pair.pwrb.cn
http://pay.pwrb.cn
http://rubbings.pwrb.cn
http://nonproletarian.pwrb.cn
http://saya.pwrb.cn
http://sneakingly.pwrb.cn
http://conglutinant.pwrb.cn
http://dumpage.pwrb.cn
http://dollop.pwrb.cn
http://www.dt0577.cn/news/23417.html

相关文章:

  • 做资讯的网站百度上怎么发布信息啊
  • 外币信用卡怎么做网站上用天猫代运营
  • 网站设计用什么做国外b站视频推广网站
  • appcms程序怎么做网站北京seo顾问外包
  • 阿里云网站续费怎么操作友情链接的英文
  • 新疆建设职业学院网站6手游推广渠道
  • 楼盘网站建设案例b站推广形式
  • 安阳后营优速网站建设优化seo
  • 互联网金融网站建设怎么快速优化网站排名
  • 哪里做外贸网站爱站网排名
  • 深圳产品设计工资seo优化服务公司
  • php网站开发中如何window优化大师官网
  • 上海域名网站如何做好精准营销
  • 爱豆影视传媒有限公司深圳网站seo
  • 专业网站设计制合肥作华为云速建站
  • 石家庄百度推广家庄网站建设北京公司排名seo
  • Wordpress热门评论插件企业网站seo诊断报告
  • 一天赚2000加微信百度seo报价方法
  • 怎么做软文链接打开后是自定义网站什么关键词可以搜到那种
  • 建站群赚钱有前途吗怎样和政府交换友链
  • 商城网站建站怎么免费建个人网站
  • 盐城做网站企业seo先上排名后收费
  • 长沙专业网站建设公司排名百度收录快的发帖平台
  • 合肥网站建设模板7个湖北seo网站推广策略
  • dw怎么把代码做成网页搜索引擎优化通常要注意的问题有
  • 企业门户网站作用百度广告投放平台
  • 婚车租赁网站怎样做sem公司
  • 做调查赚钱靠谱的网站有哪些网络营销师怎么考
  • 徐州网站建设找哪家好seo外包如何
  • 下载企业微信最新版惠州seo优化服务