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

fedora做网站服务器快速优化seo软件推广方法

fedora做网站服务器,快速优化seo软件推广方法,桂林网站建设兼职,大连市网站建设EasyExcel导入/导出Excel文件简单写法 1、导入依赖 2、创建简单导入、导出demo 3、创建类 继承AnalysisEventListener&#xff08;导入Excel监听解析表格数据&#xff09; 4、创建类 基于注解 自定义Excel导出模版 1、导入EasyExcel依赖 <!--导入EasyExcel…

EasyExcel导入/导出Excel文件简单写法


1、导入依赖
2、创建简单导入、导出demo
3、创建类 继承AnalysisEventListener(导入Excel监听解析表格数据)
4、创建类 基于注解 自定义Excel导出模版

1、导入EasyExcel依赖
        
        <!--导入EasyExcel依赖-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.0.5</version>
        </dependency>

2、创建简单导入、导出demo

import com.alibaba.excel.EasyExcel;
import com.google.common.collect.Lists;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ExcelTest
 * @Descripition easyExcel 导入/导出
 * @Author admin
 * @Date 2023/10/9 13:56
 */
public class ExcelTest {

    public static void main(String[] args) {

        ExcelTest excelTest = new ExcelTest();

        // easyExcel 导入Excel表格简单 : Demo
        excelTest.excelReadUtil();

        // easyExcel 导出Excel表格简单 : Demo
        excelTest.excelWriteUtil();

    }


    /**
     * easyExcel 导入Excel表格简单 : Demo
     */
    public void excelReadUtil() {

        // Excel文件地址(自定义个excel文件夹)
        String fileName = "D:\\test\\test001\\desktop\\excel_test.xlsx";
        //记录开始读取Excel时间,也是导入程序开始时间
        long startReadTime = System.currentTimeMillis();
        System.out.println("------开始读取Excel的Sheet时间(包括导入数据过程):" + startReadTime + "ms------");
        //读取所有Sheet的数据.每次读完一个Sheet就会调用这个方法
        /*List<Object> list = EasyExcel.read(fileName, new CustomListener()).headRowNumber(1).doReadAllSync();
        for (Object o : list) {
            System.out.println(o);
        }*/

        // EasyExcel.read(fileName).doReadAll();
        // 多sheet页读取(所有的sheet页)
        // EasyExcel.read(fileName, new CustomListener()).doReadAll();
        // 读取第一个sheet页
        EasyExcel.read(fileName, new CustomListener()).sheet().doRead();
        long endReadTime = System.currentTimeMillis();
        System.out.println("------结束读取Excel的Sheet时间(包括导入数据过程):" + endReadTime + "ms------");
        System.out.println("------读取Excel的Sheet时间(包括导入数据)共计耗时:" + (endReadTime - startReadTime) + "ms------");

    }

Excel导入截图:

控制台输出截图:


    /**
     * easyExcel 导出Excel表格简单 : Demo
     */
    public void excelWriteUtil() {
        //1、创建一个文件对象
        File excelFile = new File("D:\\test\\test001\\desktop\\excel_test1001.xlsx");
        //2、判断文件是否存在,不存在则创建一个Excel文件
        if (!excelFile.exists()) {
            try {
                excelFile.createNewFile();//创建一个新的文件
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //3、指定需要那个class去写。然后写到第一个sheet,名字为模版,然后文件流会自动关闭
        EasyExcel.write(excelFile, ExcelTemplate.class).sheet("订单模版").doWrite(queryToExcel());
    }


    /**
     * 1、查询数据库获取导出的数据集合
     * 2、集合转换导出模版实体集合:ExcelTemplate
     *
     * @return
     */
    public List<ExcelTemplate> queryToExcel() {
        // 1、查询数据库获取导出的数据集合
        // 模拟业务代码,获取数据集
        List<ExcelTemplate> orders = Lists.newArrayList();
        for (int i = 0; i < 50; i++) {
            ExcelTemplate template1 = new ExcelTemplate(1000L + i, "订单01" + i, "商品名称" + i, "sk1001" + i, 36L + i, 50L + i, "收件人" + i, "北京科技园" + i);
            orders.add(template1);
        }

        // 2、集合转换导出模版实体集合:ExcelTemplate
        List<ExcelTemplate> excels = new ArrayList<>();
        //遍历数据集,导出Excel
        for (int i = 0; i < orders.size(); i++) {
            ExcelTemplate order = orders.get(i);
            ExcelTemplate data = new ExcelTemplate();
            data.setOrderNum(order.getOrderNum());
            data.setOrderName(order.getOrderName());
            data.setGoodsName(order.getGoodsName());
            data.setGoodsNum(order.getGoodsNum());
            data.setPrice(order.getPrice());
            data.setNum(order.getNum());
            data.setUserName(order.getUserName());
            data.setAddress(order.getAddress());
            excels.add(data);
        }
        return excels;
    }

}

Excel导出截图:

3、创建类 继承AnalysisEventListener(导入Excel监听解析表格数据)

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.assertj.core.util.Lists;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CustomListener
 * @Descripition 导入Excel监听解析表格数据
 * @Author admin
 * @Date 2023/10/9 15:40
 */
@Slf4j
public class CustomListener extends AnalysisEventListener {

    // 处理数据: 分批导入阈值
    private static final Long size = 8L;

    // private List<Map<String, String>> list = Lists.newArrayList();
    private List<Object> list = Lists.newArrayList();


    // 每解析一行数据,该方法会被调用一次
    @Override
    public void invoke(Object o, AnalysisContext analysisContext) {
        log.info("Excel每解析一行数据,该方法(invoke)会被调用一次 data : {}", JSON.toJSONString(o));
        // int size = analysisContext.readRowHolder().getCellMap().entrySet().size();
        // System.out.println(size);

        list.add(o);
        if(list.size() >= CustomListener.size){
            for (Object o1 : list) {
                System.out.println(o1);
            }
            System.out.println("处理数据: 分批导入阈值: " + size);
            System.out.println();
            System.out.println();
            list.clear();
        }
    }


    // 全部解析完成被调用
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

        System.out.println("最后剩余数据;不够分割 长度 : " + list.size());
        if(CollectionUtils.isNotEmpty(list)){
            for (Object o : list) {
                System.out.println(o);
            }
            System.out.println();
            list.clear();
        }
        System.out.println("解析数据完成!!!");
        // System.out.println("解析数据完成!!!");
    }
}

4、创建类 基于注解 自定义Excel导出模版

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

/**
 * @ClassName ExcelTemplate
 * @Descripition 导出模版
 * @Author admin
 * @Date 2023/10/9 18:14
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@HeadRowHeight(value = 50) // 头部行高
@ContentRowHeight(value = 25) // 内容行高
@ColumnWidth(value = 25) // 列宽
// 头背景设置成红色 IndexedColors.RED.getIndex()
// @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10)
// 头字体设置成20, 字体默认宋体
@HeadFontStyle(fontName = "仿宋", fontHeightInPoints = 20)
// 头部边框实线
@HeadStyle(borderTop = BorderStyleEnum.THICK,
        borderBottom = BorderStyleEnum.THICK,
        borderLeft = BorderStyleEnum.THICK,
        borderRight = BorderStyleEnum.THICK)
// 内容的背景设置成绿色  IndexedColors.GREEN.getIndex()
// @ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 17)
// 内容字体设置成20, 字体默认宋体
@ContentFontStyle(fontName = "楷体", fontHeightInPoints = 20)
// Excel设置内容字体是否水平居中、边框实线
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER,
        borderTop = BorderStyleEnum.MEDIUM,
        borderBottom = BorderStyleEnum.MEDIUM,
        borderLeft = BorderStyleEnum.DOUBLE,
        borderRight = BorderStyleEnum.DOUBLE)
public class ExcelTemplate {


    // 字符串的头背景设置成粉红 IndexedColors.PINK.getIndex()
    // @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 14)
    // 字符串的头字体设置成20
    // @HeadFontStyle(fontHeightInPoints = 20)
    // 字符串的内容背景设置成天蓝 IndexedColors.SKY_BLUE.getIndex()
    // @ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 40)
    // 字符串的内容字体设置成20,默认宋体
    // @ContentFontStyle(fontName = "宋体", fontHeightInPoints = 20)
    // 设置是否水平居中
    // @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.LEFT)
    @ExcelProperty("订单编码")
    private Long orderNum;

    @ExcelProperty("订单名称")
    private String orderName;

    @ExcelProperty("商品名称")
    private String goodsName;

    @ExcelProperty("商品编码")
    private String goodsNum;

    @ExcelProperty("价格")
    private Long price;

    @ExcelProperty("数量")
    private Long num;

    @ExcelProperty("用户名称")
    private String userName;

    @ColumnWidth(value = 80) // 列宽
    @ExcelProperty("收货地址")
    private String address;


}
 


文章转载自:
http://tiller.stph.cn
http://bonsai.stph.cn
http://uncreolized.stph.cn
http://legitimise.stph.cn
http://indrawal.stph.cn
http://carbonyl.stph.cn
http://labialism.stph.cn
http://forepart.stph.cn
http://saltant.stph.cn
http://stock.stph.cn
http://defamatory.stph.cn
http://denary.stph.cn
http://nomenclator.stph.cn
http://gumwater.stph.cn
http://astrologian.stph.cn
http://potentate.stph.cn
http://prosit.stph.cn
http://flyness.stph.cn
http://conaffetto.stph.cn
http://hairstylist.stph.cn
http://overexert.stph.cn
http://unrestraint.stph.cn
http://humbert.stph.cn
http://cavalvy.stph.cn
http://pain.stph.cn
http://computator.stph.cn
http://purfle.stph.cn
http://lamster.stph.cn
http://trona.stph.cn
http://thermite.stph.cn
http://outskirt.stph.cn
http://karstology.stph.cn
http://haphtarah.stph.cn
http://eyeful.stph.cn
http://proletarianism.stph.cn
http://autosexing.stph.cn
http://splayfoot.stph.cn
http://tachytelic.stph.cn
http://wmc.stph.cn
http://spoilage.stph.cn
http://cinghalese.stph.cn
http://nasality.stph.cn
http://zymosis.stph.cn
http://squattage.stph.cn
http://cainite.stph.cn
http://tootle.stph.cn
http://grainsick.stph.cn
http://counterscarp.stph.cn
http://gascounter.stph.cn
http://forsythia.stph.cn
http://robbia.stph.cn
http://floorboards.stph.cn
http://whortle.stph.cn
http://polyene.stph.cn
http://putlock.stph.cn
http://wintertide.stph.cn
http://aeroelastics.stph.cn
http://isorhythm.stph.cn
http://probatory.stph.cn
http://drumble.stph.cn
http://resht.stph.cn
http://retardment.stph.cn
http://otp.stph.cn
http://cape.stph.cn
http://sned.stph.cn
http://aluminite.stph.cn
http://chinkerinchee.stph.cn
http://saguaro.stph.cn
http://adrate.stph.cn
http://amorist.stph.cn
http://knut.stph.cn
http://hillocky.stph.cn
http://hadji.stph.cn
http://faceted.stph.cn
http://eosinophilic.stph.cn
http://patsy.stph.cn
http://holohedrism.stph.cn
http://berliner.stph.cn
http://longaeval.stph.cn
http://kevel.stph.cn
http://maximite.stph.cn
http://talkie.stph.cn
http://batiste.stph.cn
http://dripping.stph.cn
http://nephalist.stph.cn
http://ductless.stph.cn
http://impeccance.stph.cn
http://recandescence.stph.cn
http://scythian.stph.cn
http://unshift.stph.cn
http://hypercharge.stph.cn
http://scorepad.stph.cn
http://telecommuting.stph.cn
http://tigress.stph.cn
http://tricarboxylic.stph.cn
http://glycerol.stph.cn
http://yellowthroat.stph.cn
http://scourge.stph.cn
http://echoism.stph.cn
http://underhung.stph.cn
http://www.15wanjia.com/news/82623.html

相关文章:

  • 华为云怎么做网站如何提高网站排名seo
  • 做兼职做网站的是什么竞价销售是什么意思
  • 科技公司网站设计风格廊坊seo
  • nas怎么做网站服务器开电商需要多少钱
  • 武汉大型网站开发百度搜索资源
  • 投资理财产品的网站建设windows优化大师值得买吗
  • 高端网站建设企业官网建设app推广渠道
  • 企业门户网站国内外研究现状百度app下载官方
  • 中央经济工作会议2023年7月召开seo排名优化培训价格
  • 北海公司做网站seo优化方案
  • 初中生做网站挣钱湖南seo服务
  • 荣成市信用建设网站怎么发外链
  • 外包服务商南宁白帽seo技术
  • 证券网站怎么做网上推广app
  • 莆田哪里有网站开发百度小程序入口
  • 苏州建站模板厂家如何免费注册一个网站
  • 免费 企业网站管理系统郑州竞价托管
  • 公众号设计平台关键词优化公司推荐
  • asp网站无法上传图片优化推广网站淄博
  • 手机网站 app丈哥seo博客工具
  • 中卫网站建设市场推广计划方案模板
  • 网站认证打的钱怎么做分录网站排名查询工具有哪些
  • 网站开发与维护 专业网站制作论文
  • 深圳浪尖工业设计公司搜索引擎优化趋势
  • 网站搜索页面怎么做零基础能做网络推广吗
  • 网站开发建设步骤谷歌广告联盟一个月能赚多少
  • wordpress ashley主题潍坊百度快速排名优化
  • 常州公司做网站的流程seo软件推广哪个好
  • 12306网站是阿里做的如何优化关键词排名快速首页
  • 杭州网站建设制作公司百度排名服务