Java使用poi导出excel表格如何合并相同内容的行

poi实现对树形结构数据导出excel并合并表格 poi实现对树形结构数据导出excel并合并表格 最近好像得罪了poi,遇到的都是导出word、Excel、pdf的问题。下面我记录一下poi对树形结构的处理,前面先梳理整体思路,文章末尾会贴上完整代码。 首先我们看一下模板和效果图吧: 怎么样,效果还行吧,有没有达到你心目中的标准?如果你也遇到了这样的问题,那么请静下心来花费几分钟时间,我会详细的梳理出自己的思路,希望能够帮助到你。 现在开始... 阅读详情

记录一个开发过程中遇到的poi导出excel问题

一般的poi导出格式为以下这种
在这里插入图片描述
这种实现起来也简单, 只需要配置好格式, 写好标题, 将数据循环导出到excel就行了 , 可是下面这种就比较难搞了
在这里插入图片描述
由于第一列需要根据日期合并行, 而且行数不是固定的, 是需要根据上面的筛选条件, 查询出来, 将结果按照日期分组合并, 所以左边第一列需要合并的行是灵活多变的, 不能简单按照合并列那样。
下面是我的解决方案, 如有意见, 请多多指教
这是数据库里的数据
在这里插入图片描述

实现逻辑和代码

1. 首先应该将数据按照日期排序, 查询出来

mapper.xml

    <select id="getDetail" resultType="com.XXX.pojo.dto.data.ActivityAnalysisDTO">
        select
        aa.*,
        cp.name as platform_name
        from activity_analysis aa
        left join cplatform cp on cp.cid = aa.platform_id
        <include refid="searchActivity"/>
        order by aa.create_time asc,aa.platform_id asc
    </select>
<sql id="searchActivity">
        <where>
            1=1
            <if test="startTime!=null and endTime!=null">
                and aa.create_time between #{startTime} and #{endTime}
            </if>
            <if test="activityId!=null">
                and aa.activity_id = #{activityId}
            </if>
            <if test="typeId!=null">
                and aa.type_id = #{typeId}
            </if>
            <if test="platformId!=null">
                and aa.platform_id = #{platformId}
            </if>
        </where>
    </sql>

我这里直接使用的查询这个活动数据的接口
这里主要是想和活动详情使用同样的接口, 日后修改起来, 也方便些(也可使用单独查询列表的接口)
service
由于HashMap集合中key是无序的, 所以, 在这里我将HashMap转为LinkedHashMap, 有序

public Map<String, List<ActivityAnalysisDTO>> getDetail(SearchActivityArgs args) {
   
   
        //1.查找活动详情
        List<ActivityAnalysisDTO> activityAnalysisDTOList = activityAnalysisMapper.getDetail(args);
        Map<String, List<ActivityAnalysisDTO>> mapStrKey = new HashMap<>();
        //将Date类型的key转化为String 类型的key, 将数据按照创建日期分组, 构建
        if (CollectionUtils.isNotEmpty(activityAnalysisDTOList)) {
   
   
            Map<Date, List<ActivityAnalysisDTO>> listMap = activityAnalysisDTOList.stream().collect(Collectors.groupingBy(o -> o.getCreateTime()));
            for (Date date : listMap.keySet()) {
   
   
                mapStrKey.put(DateUtils.getStringFromDate(date, "yyyy-MM-dd"), listMap.get(date));
            }
        }
        LinkedHashMap<String, List<ActivityAnalysisDTO>> sortMap = this.sortKeyMap(mapStrKey);
        return sortMap;
    }

    /**
     * 给map集合按照key排序
     *
     * @param oriMap
     * @return
     */
    private LinkedHashMap<String, List<ActivityAnalysisDTO>> sortKeyMap(Map<String, List<ActivityAnalysisDTO>> oriMap) {
   
   
        LinkedHashMap<String, List<ActivityAnalysisDTO>> sortKeyMap = new LinkedHashMap<>();
        if (oriMap != null) {
   
   
            Set<String> set = oriMap.keySet();
            Object
Apache POI读合并单元格 利用Apache POI读合并单元格。 阅读详情

相关推荐

java统计报表,导出excel,自定义存储目录

java统计报表,导出excle,自定义存储目录 做一个将查询出来的数据写入excel,并且点击导出按钮是,可以选择导出路径 **直接上完整代码 1.utils工具类,里面可以自己设置样式,详细看注释 import java.io.File; import java.io.FileOutputStream; import org.apache.commons.io.FileUtils; import org.apache.poi.hssf.usermodel.*; import org.apache.poi

weixin_49462255的博客 1252

POI操作 导出Excel表格

POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFCellStyle setBorder = wb.createCellStyle(); 一、设置背景色: setBorder

yang_best的专栏 4449

Java导出excel时合并同一列中相同内容的行思路详解

主要介绍了Java导出excel时合并同一列中相同内容的行,需要的朋友可以参考下

ACM论文LaTeX模板解析(三)| 文章顶部信息(Top matter))Part 1

文章顶部信息(Top matter))Part 1,文章类型、作者信息等

FreshManInC的博客 4856

动态数据脱敏技术分析

在当前国内信息安全热潮中,数据脱敏作为数据安全的重要一环得到了业界的认可与重视。早在2012年,数据脱敏首次作为一个单独的魔力象限由Gartner发布,Gartner在2014年又提出了:按照数据使用场景,将数据脱敏分为静态数据脱敏(Static data masking-SDM )与动态数据脱敏(Dynamic data masking-DDM )。 可能有人望文生义,认为动态数据脱敏一定比静态数据脱敏高级。非也非也,静态or动态,取决于脱敏的使用场景,主要是以使用场景为由来选择合适的数据脱敏的模式。 本

美创科技的博客 4684

ECB oracle——attack

基于ECB oracle的攻击方案前言什么是ECB方案步骤1.确定块大小和明文大小2.暴力破解求明文脚本代码 前言 参考文章:Breaking ECB by prepending your own message. 环境地址:ECB oracle 什么是ECB 分组密码中AES的一种模式(其他还有:CBC、ECB、CTR、OCF、CFB)如图每一块加密是分开的。 方案步骤 1.确定块大小和明文大小 先用一个字符"a"去encrypt返回32个字节的数据(64位16进制)依次用"aa",“aaa”…去en

weixin_44617902的博客 1313

Vivado 2021.1 实战:手把手教你用IEEE1735 V2加密你的Verilog源码(附完整TCL命令)

本文详细介绍了在Vivado 2021.1中使用IEEE1735 V2标准加密Verilog源码的全流程,包括许可证申请、密钥文件配置、TCL命令执行及加密后验证。通过实战步骤和完整TCL命令,帮助开发者有效保护FPGA设计知识产权,确保核心算法安全。

weixin_42706667的博客 197

FAA和EASA在机载电子硬件适航中的发展历史与差异

FAA和EASA在机载电子硬件的适航审查中虽然存在一些差异,但通过近年来的合作,这些差异正在逐步缩小。两者通过。

qq_41854911的博客 750

科研绘图系列:R语言circos图(circos plot)

科研绘图系列:R语言circos图(circos plot)

专注生信领域 3444

ubuntu 安装node和npm

在ubuntu中经常需要用到node ,npm,因为npm基本会和node同时安装,所以只需要安装node即可。可以使用 nvm(Node Version Manager)来管理你的 Node.js 版本。

风吹落叶的博客 2294

Spring Boot集成ShardingSphere实现数据加密及数据脱敏 | Spring Cloud 48

利用ShardingSphere实现: - 数据加密 - 数据脱敏

gmHappy 1万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: lambda表达式的使用总结
下一篇: mybatis中orderBy(排序字段)和sort(排序方式)引起的bug
意田天
博客等级 码龄7年 41粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

意田天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值