kongzy
2024-07-12 28aaf2ffa1dbb860a292ba330a7e9362e60e7832
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.gkhy.admin;
 
import com.alibaba.excel.EasyExcel;
import com.gkhy.assess.admin.GkhyAdminApplication;
import com.gkhy.assess.system.excel.ExpertExcelListener;
import com.gkhy.assess.system.domain.vo.SysExpertInfoExcelVO;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.test.context.junit4.SpringRunner;
 
import java.io.IOException;
import java.io.InputStream;
 
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GkhyAdminApplication.class)
//@ActiveProfiles("dev")
@Slf4j
public class ExcelTest {
    @Autowired
    private ApplicationContext applicationContext;
 
    @Test
    public void testExcel() throws IOException {
        Resource resource = applicationContext.getResource("classpath:abc.xlsx");
        InputStream resourceAsStream =resource.getInputStream();
        EasyExcel.read(resourceAsStream, SysExpertInfoExcelVO.class,new ExpertExcelListener()).sheet(0).doRead();
    }
}