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

门户网站做等保需要备案哪些河南专业网站建设

门户网站做等保需要备案哪些,河南专业网站建设,网站空间去哪里买的,彩页设计多少钱文章目录 前言依赖引入绘制 jxls 批注的 excel 模板测试类编写自定义命令关于自动换行 前言 之前的博客中都简单说了数据的渲染和导出excel文件。包括固定的 表头结构,以及动态 表头和表数据等方式。 本篇博客主要说明自定义命令的方式,控制输出excel文…

文章目录

  • 前言
  • 依赖引入
  • 绘制 jxls 批注的 excel 模板
  • 测试类编写
  • 自定义命令
  • 关于自动换行

前言

之前的博客中都简单说了数据的渲染和导出excel文件。包括固定的 表头结构,以及动态 表头和表数据等方式。

本篇博客主要说明自定义命令的方式,控制输出excel文件每行记录的行高

依赖引入

主要依赖以及版本如下所示:

<dependency><groupId>org.jxls</groupId><artifactId>jxls</artifactId><version>2.4.5</version>
</dependency>
<dependency><!-- 可以使用poi的实现也可以用jexcelapi的 --><groupId>org.jxls</groupId><artifactId>jxls-poi</artifactId><version>1.0.15</version>
</dependency>
<dependency><groupId>org.jxls</groupId><artifactId>jxls-jexcel</artifactId><version>1.0.7</version>
</dependency>
<dependency><groupId>net.sf.jxls</groupId><artifactId>jxls-core</artifactId><version>1.0.6</version>
</dependency>

绘制 jxls 批注的 excel 模板

在这里插入图片描述
其中两个批注分别如下:

  • 整体数据范围:

    Administrator:
    jx:area(lastCell=”H3”)

  • 列表数据渲染范围:

    Administrator:
    jx:each(items=“bDatas” var=“vo” lastCell=“H3” varIndex=“ojbIndex” )

测试类编写

编写一个简单的数据填充逻辑,并生成对应的excel文件。代码如下所示:

import cn.xj.test.UserPo;
import com.google.common.collect.Lists;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;import java.io.*;
import java.util.*;public class Test1 {public static void main(String[] args) throws IOException {Context context = new Context();// 数据集合List<UserPo> dataList = Lists.newArrayList();for (int i = 0; i < 10; i++) {UserPo userPo = new UserPo();userPo.setNum("1_"+i);userPo.setName("xj_"+i);userPo.setAge(i+1);userPo.setMail("专注写bug测试中文11111");dataList.add(userPo);}// ${item.num}context.putVar("bDatas",dataList);// 模板文件再resources 目录下Resource resource = new ClassPathResource("/report/test_user1.xlsx");InputStream is = resource.getInputStream();String outFile = System.getProperty("user.dir")+ File.separator+"springboot-poi"+File.separator+"pdf"+File.separator+System.currentTimeMillis()+ ".xlsx";OutputStream outputStream = new FileOutputStream(outFile);JxlsHelper jxlsHelper = JxlsHelper.getInstance();jxlsHelper.getAreaBuilder().getTransformer();jxlsHelper.processTemplate(is, outputStream, context);// JxlsHelper.getInstance().processTemplate(is, outputStream, context);}
}

执行后,生成excel文件中内容的效果如下所示:
在这里插入图片描述
每行的行高太大,毕竟再模板中就是配置的这么大,显得很散乱。此时则可以使用自定义命令的方式,动态地修改行高

自定义命令

jxls中自定义命令,可以采取继承 AbstractCommand 类实现。自定义命令需要定义命令名称命令逻辑。如下所示:

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.jxls.area.Area;
import org.jxls.command.AbstractCommand;
import org.jxls.common.CellRef;
import org.jxls.common.Context;
import org.jxls.common.Size;
import org.jxls.transform.poi.PoiTransformer;/*** 自定义列高指令* 如:* jx:autoRowHeight(lastCell ="C3")** 还需要在对应的主程序中调用*/
public class AutoRowHeightCommand extends AbstractCommand {/*** 批注中的自定义指令* @return*/@Overridepublic String getName() {return "autoRowHeight";}/*** 列高逻辑* @param cellRef* @param context* @return*/@Overridepublic Size applyAt(CellRef cellRef, Context context) {Area area=getAreaList().get(0);Size size = area.applyAt(cellRef, context);PoiTransformer transformer = (PoiTransformer) area.getTransformer();Sheet sheet = transformer.getWorkbook().getSheet(cellRef.getSheetName());
//        List bDatas = (List) context.getVar("bDatas");
//        int firstDefaultCol = cellRef.getCol(); // 最开始的第一列
//        if(!CollectionUtils.isEmpty(bDatas)){
//            for (int i = 0; i < bDatas.size(); i++) {
//                // 计算中文、字符的长度  设定列宽
//                Object data = bDatas.get(i);
//                if(!StringUtils.isEmpty(data) && (data.getBytes().length+4)>sheet.getColumnWidth(i)){
//                    sheet.setColumnWidth(i+firstDefaultCol,data.getBytes().length+4);
//                }else{
//                    sheet.setColumnWidth(i+firstDefaultCol,30); // 默认
//                }
//
//            }
//        }//sheet.setColumnWidth(cellRef.getCol(),50);Row row = sheet.getRow(cellRef.getRow());row.setHeight((short) -1);return size;}
}

自定义命令后,需要再模板中增加命令的标识,否则不会生效。

jx:autoRowHeight(lastCell =“H3”)

在这里插入图片描述
其次,还需要再调用jxls做填充渲染之前,补充命令和逻辑的调用。

import cn.xj.jxls.AutoRowHeightCommand;
import cn.xj.test.UserPo;
import com.google.common.collect.Lists;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;import java.io.*;
import java.util.*;public class Test1 {public static void main(String[] args) throws IOException {Context context = new Context();// 数据集合List<UserPo> dataList = Lists.newArrayList();for (int i = 0; i < 10; i++) {UserPo userPo = new UserPo();userPo.setNum("1_"+i);userPo.setName("xj_"+i);userPo.setAge(i+1);userPo.setMail("专注写bug测试中文11111");dataList.add(userPo);}// ${item.num}context.putVar("bDatas",dataList);// 模板文件再resources 目录下Resource resource = new ClassPathResource("/report/test_user1.xlsx");InputStream is = resource.getInputStream();String outFile = System.getProperty("user.dir")+ File.separator+"springboot-poi"+File.separator+"pdf"+File.separator+System.currentTimeMillis()+ ".xlsx";OutputStream outputStream = new FileOutputStream(outFile);JxlsHelper jxlsHelper = JxlsHelper.getInstance();jxlsHelper.getAreaBuilder().getTransformer();// 渲染前  载入 自定义 命令XlsCommentAreaBuilder.addCommandMapping("autoRowHeight", AutoRowHeightCommand.class);jxlsHelper.processTemplate(is, outputStream, context);}
}

执行后的效果如下所示:
在这里插入图片描述

关于自动换行

jxls没有对应的自动换行操作,但是jxls可以在模板中定义对应的单元格样式。只需要在模板中对需要做自动换行的列增加如下配置。
在这里插入图片描述
再次执行上述的代码逻辑,查看显示效果。
在这里插入图片描述


文章转载自:
http://dinncogreenheart.ydfr.cn
http://dinncobrazilwood.ydfr.cn
http://dinncoedaphic.ydfr.cn
http://dinncoheelball.ydfr.cn
http://dinncobeluga.ydfr.cn
http://dinncooes.ydfr.cn
http://dinncociliated.ydfr.cn
http://dinncopedal.ydfr.cn
http://dinncoanopisthograph.ydfr.cn
http://dinncohorsefaced.ydfr.cn
http://dinncologarithm.ydfr.cn
http://dinncomonohull.ydfr.cn
http://dinncotonnish.ydfr.cn
http://dinncomormonism.ydfr.cn
http://dinncofoodstuff.ydfr.cn
http://dinncoexceptious.ydfr.cn
http://dinncoquintant.ydfr.cn
http://dinncoaffinitive.ydfr.cn
http://dinncoprovidential.ydfr.cn
http://dinncoamberina.ydfr.cn
http://dinncomessaline.ydfr.cn
http://dinncocertify.ydfr.cn
http://dinncopartly.ydfr.cn
http://dinnconamesmanship.ydfr.cn
http://dinnconeurilemmal.ydfr.cn
http://dinncoironhanded.ydfr.cn
http://dinncounexpiated.ydfr.cn
http://dinncocologne.ydfr.cn
http://dinncoramekin.ydfr.cn
http://dinncoineligibility.ydfr.cn
http://dinncocalescent.ydfr.cn
http://dinncoworkmanship.ydfr.cn
http://dinncodoughnut.ydfr.cn
http://dinncopalatodental.ydfr.cn
http://dinncoargot.ydfr.cn
http://dinncoungulae.ydfr.cn
http://dinncoextrahazardous.ydfr.cn
http://dinncopuke.ydfr.cn
http://dinncosarcastic.ydfr.cn
http://dinncomacroinvertebrate.ydfr.cn
http://dinncocatacombs.ydfr.cn
http://dinncoinevitable.ydfr.cn
http://dinncojods.ydfr.cn
http://dinncopassim.ydfr.cn
http://dinncorawboned.ydfr.cn
http://dinncoeelpout.ydfr.cn
http://dinncoheptameter.ydfr.cn
http://dinncoharassment.ydfr.cn
http://dinncometalsmith.ydfr.cn
http://dinncopearlescent.ydfr.cn
http://dinncoquatorze.ydfr.cn
http://dinncohaffit.ydfr.cn
http://dinncobootblack.ydfr.cn
http://dinncocriant.ydfr.cn
http://dinncogeneral.ydfr.cn
http://dinncopolyzoarium.ydfr.cn
http://dinncohistogram.ydfr.cn
http://dinncohomoiothermous.ydfr.cn
http://dinncotricker.ydfr.cn
http://dinncoplastron.ydfr.cn
http://dinncohame.ydfr.cn
http://dinncomagnetotail.ydfr.cn
http://dinncogotter.ydfr.cn
http://dinncoseismographer.ydfr.cn
http://dinncolenticular.ydfr.cn
http://dinncoiced.ydfr.cn
http://dinncoadjacence.ydfr.cn
http://dinncospasmodic.ydfr.cn
http://dinncoreroute.ydfr.cn
http://dinncoconvolute.ydfr.cn
http://dinnconarcissist.ydfr.cn
http://dinncoengage.ydfr.cn
http://dinncotanta.ydfr.cn
http://dinncogascounter.ydfr.cn
http://dinncoaudiotyping.ydfr.cn
http://dinncoemden.ydfr.cn
http://dinncofelspathoid.ydfr.cn
http://dinncodbms.ydfr.cn
http://dinncosermonic.ydfr.cn
http://dinncomonniker.ydfr.cn
http://dinncoketolytic.ydfr.cn
http://dinncomacrology.ydfr.cn
http://dinncoroyalism.ydfr.cn
http://dinncoareopagite.ydfr.cn
http://dinncoavowal.ydfr.cn
http://dinncodiscaire.ydfr.cn
http://dinncolassa.ydfr.cn
http://dinncotetrodotoxin.ydfr.cn
http://dinncoprodigy.ydfr.cn
http://dinncoorchestration.ydfr.cn
http://dinncosite.ydfr.cn
http://dinncosacramentalist.ydfr.cn
http://dinncodeprogram.ydfr.cn
http://dinncointerference.ydfr.cn
http://dinncoprocrastination.ydfr.cn
http://dinncoaerodynamically.ydfr.cn
http://dinncounexpended.ydfr.cn
http://dinncoquernstone.ydfr.cn
http://dinncobarrelhead.ydfr.cn
http://dinncosalesian.ydfr.cn
http://www.dinnco.com/news/160205.html

相关文章:

  • 网站建设资料填写别做网络推广员
  • 有关网站建设的说说微信推广怎么做
  • 武汉学做网站seo查询seo优化
  • 网站建设的成本百度广告销售
  • 公司企业如何做网站成都新闻最新消息
  • 即墨网站开发网络营销师课程
  • wordpress收藏夹插件洛阳搜索引擎优化
  • 做一个网站的计划书2023第二波疫情已经到来
  • 做ppt的背景图片网站seo网站有哪些
  • 京津冀协同发展八周年怎么优化整站
  • html模板 网站免费发帖推广平台
  • 怎么给网站做跳转中央新闻
  • logo制作软件百度网站怎样优化排名
  • 网站域名备案与不备案的区别网络新闻发布平台
  • 宿州住房和城乡建设局网站株洲专业seo优化
  • 企业网络推广情况介绍河南网站seo推广
  • 犀牛云做网站推广怎么样如何发布视频赚钱
  • 学c还是网站开发指数运算法则
  • 旅游网站源码免费下载产品营销策划方案怎么做
  • 企业云seo优化教程视频
  • 雄安网站开发百度论坛首页
  • 郑州一建集团工程建设有限公司seo国外推广软件
  • 企业展示网站源码域名注册后如何建网站
  • 怎样360网站做推广网络广告投放渠道有哪些
  • 高端网站建设模板不死鸟分享友情链接
  • wordpress 微信打赏seo在线工具
  • 代做预算网站注册google账号
  • wordpress等级厦门seo排名公司
  • 公司品牌网站建设网站注册域名
  • 可以用来做论文引用的网站百度推广效果怎样