当前位置:网站首页>Use tool classes to read Excel files according to certain rules
Use tool classes to read Excel files according to certain rules
2022-06-11 04:11:00 【Question mark we are friends】
You need to add data in batches according to the function classification , The data carrier is Excel file . Now write a tool class to read and process according to business rules Excel File data .
Catalog
1. Tool class
Read the file here , Use hutool To process data ; adopt ExcelReader Alias handling method to give Excel Add mapping relationship to the header in , So that data can correspond to specific entity classes .
The code is as follows ( Example ):
package com.aisino.common.utils;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.aisino.common.core.domain.entity.Inter;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* Created by lijindong on 2022-05-30 17:36
*/
public class ExcelUtils {
/**
* description: Use the tool class to get Excel Interface information in the file
* create by: lee
*/
public static List<Inter> getInterrInfoByHutool(File file) {
ExcelReader excelReader = ExcelUtil.getReader(file);
excelReader.addHeaderAlias(" The name of the interface ","interName");
excelReader.addHeaderAlias(" Call mode ","callMethod");
excelReader.addHeaderAlias("URL","operUrl");
excelReader.addHeaderAlias(" Interface status ","interStatus");
List<Inter> interList = excelReader.readAll(Inter.class);
excelReader.close();
return interList;
}
/**
* MultipartFile Convert to File file
*
* @param multipartFile
* @return
*/
public final static File transferToFile(MultipartFile multipartFile) {
// Choose to implement this transformation with a buffer, that is, use java Temporary files created Use MultipartFile.transferto() Method .
File file = null;
try {
String originalFilename = multipartFile.getOriginalFilename();
// Get file suffix
String prefix = originalFilename.substring(originalFilename.lastIndexOf("."));
file = File.createTempFile(originalFilename, prefix); // Create temporary file
multipartFile.transferTo(file);
// Delete
file.deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
}
2. Concrete realization
The code is as follows ( Example ):
List<Inter> interList;
// from Excel Get interface information from and assemble it into the collection
File fileF = ExcelUtils.transferToFile(file);
interList = ExcelUtils.getInterrInfoByHutool(fileF);summary
That's what we're going to talk about today , This paper introduces Excel Use of tool class , It can be used to import business data in batches .
边栏推荐
- Application of NTP network time server (PTP clock synchronization) in it network
- NTP time server (GPS Beidou satellite synchronous clock) application boiler monitoring system
- It's 2022. When will the "module freedom" be realized?
- Market prospect analysis and Research Report of beam combiner in 2022
- Esp32 development -lvgl uses internal and external fonts
- Matter protocol
- unforgettable moments
- Discussion on the development trend of remote power management unit (Intelligent PDU)
- clickjacking漏洞的挖掘与利用
- Docker uses PXC to build a MySQL Cluster (mysql:5.7.24)
猜你喜欢

司马炎爷爷 告诉你什么叫做内卷!
![[cnn]|differences between CNN and transformer](/img/ed/2b47387ba390a02c24bf9ff85b36e4.png)
[cnn]|differences between CNN and transformer

Simulation of radar emitter modulated signal

代码复现CSRF攻击并解决它

Google 有哪些牛逼的开源项目?

Programming battle -- challenging college entrance examination questions

Discussion on the development trend of remote power management unit (Intelligent PDU)

写给通信年轻人的27个忠告

What great open source projects does Google have?

AI助力,释放法务势能!iTerms合同智审系统重磅发布
随机推荐
Esp32 development -lvgl uses internal and external fonts
Implementation of one-dimensional convolutional neural network CNN based on FPGA (V) data quantization (with code)
Embedded basic interface -spi
Evil CSRF
检测php网站是否已经被攻破的方法
Application of NTP network time server (PTP clock synchronization) in it network
Programming battle -- challenging college entrance examination questions
Eth Transfer
Docker uses PXC to build a MySQL Cluster (mysql:5.7.24)
Some differences between people
Esp32 gattc configuration UUID
A.前缀极差(C语言)
Red team shooting range with three-layer protection
从初代播种到落地生花,5G商用三周年“催生万物”
Embedded basic interface PWM
【CustomView】Glide+BitmapTransformation 图片上下边框波浪处理(WaveTransformation)
【CNN】|How much position information do convolutional neural networks encode?
编译原理笔记之词法分析器
开源项目 英雄联盟 之WPF
Embedded basic interface SDIO