feat(测试): 测试Excel写入和读取

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-26 08:59:53 +08:00
parent f2bc0a1bfd
commit fa58dad04b
2 changed files with 33 additions and 2 deletions

4
.gitignore vendored
View File

@ -2,6 +2,6 @@
.idea
*.iml
*.class
*Test.java
**/test/
#*Test.java
#**/test/
logs

View File

@ -0,0 +1,31 @@
package com.atguigu.spzx.manger;
import com.alibaba.excel.EasyExcel;
import com.atguigu.excel.ExcelListener;
import com.atguigu.spzx.model.vo.product.CategoryExcelVo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
public class EasyExcelTest {
private static final String filename = "F:\\java项目\\尚硅谷-尚品甄选项目\\资料\\01.xlsx";
@Test
void readDateToExcel() {
ExcelListener<CategoryExcelVo> listener = new ExcelListener<>();
EasyExcel.read(filename, CategoryExcelVo.class, listener).sheet().doRead();// 解析excel表格
List<CategoryExcelVo> dataList = listener.getDataList();
dataList.forEach(System.out::println);
}
@Test
void writeDataToExcel() {
ArrayList<CategoryExcelVo> list = new ArrayList<>();
list.add(new CategoryExcelVo(1L, "数码办公", "", 0L, 1, 1));
list.add(new CategoryExcelVo(11L, "华为手机", "", 1L, 1, 2));
EasyExcel.write(filename, CategoryExcelVo.class).sheet("分类数据1").doWrite(list);
}
}