자바 에서 Easypoi 는 엑셀 다 중 시트 가 져 오기 내 보 내기 기능 을 실현 합 니 다.
6110 단어 Easypoiexcel멀 티 시트가 져 오기 내 보 내기
Easypoi 의존 도입
<!-- EasyPoi Excel -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.2.0</version>
</dependency>
Easypoi 의 주석 사용 설명(남 겨 두 고 보면 됩 니 다)두 번 째 단 계 는 표 헤드 데이터 대상 의 실체 류 를 정의 합 니 다.(주해 의 사용 은 위의 필요 에 따라 사용 하면 됩 니 다)
@Setter
@Getter
@ToString
public class LoginCaseDto {
@Excel(name = "flag(0 ,1 )",orderNum = "1",width = 20)
private String flag;
@Excel(name = "urlid( id)",orderNum = "2",width = 20)
private String urlid;
@Excel(name = "name( )",orderNum = "3",width = 20)
private String name;
@Excel(name = "pwd( )",orderNum = "4",width = 20)
private String pwd;
@Excel(name = "desc( )",orderNum = "5",width = 40)
private String desc;
@Excel(name = "actual( )",orderNum = "6",width = 40 )
private String actual;
@Excel(name = "urlpath( )",orderNum = "7",width = 40 )
private String urlpath;
}
public class LoginUrlDto {
@Excel(name = "id( )",orderNum = "1",width = 20)
private String id;
@Excel(name = "type( )",orderNum = "2",width = 20)
private String type;
@Excel(name = "url( )",orderNum = "3",width = 40)
private String url;
}
세 번 째 단계:Easypoi 도구 류(인터넷 에서 많이 찾 았 지만 완전 하지 않 습 니 다.여기 서 보충 합 니 다)참고 문장
키 패키지 도구 클래스 다 중 sheet 가 져 오기 방법
/**
* : Excel sheet,
* @param filePath
* @param sheetIndex sheet
* @param titleRows
* @param headerRows
* @param pojoClass Excel
* @return
*/
public static <T> List<T> importExcel(String filePath,int sheetIndex,Integer titleRows, Integer headerRows, Class<T> pojoClass) {
// file Workbook, , excel sheet
ImportParams params = new ImportParams();
// sheet
params.setStartSheetIndex(sheetIndex);
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
List<T> list = null;
try {
list = ExcelImportUtil.importExcel(new File(filePath), pojoClass, params);
} catch (NoSuchElementException e) {
throw new RuntimeException(" ");
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
excel 예제 가 져 오기(sheet 색인 에 직접 전송 하여 해당 하 는 sheet 표를 가 져 옵 니 다)다 중 sheet 표 내 보 내기 방법 사용(가 져 온 다 중 sheet 표 데 이 터 를 list 집합 으로 변환 하여 새 데 이 터 를 가 져 온 후 이 방법 으로 다시 기록 해 야 합 니 다)
/**
* : sheet , List<Map<String, Object>> ,
* @ExcelEntiry sheet
* @return
*/
public static String exportSheet( Object...objects){
Workbook workBook = null;
try {
// ( excel sheet )
ExportParams deptExportParams = new ExportParams();
// sheet
deptExportParams.setSheetName(" ");
// sheet
deptExportParams.setTitle(" ");
// sheet1 map
Map<String, Object> deptExportMap = new HashMap<>();
// title ExportParams , ExportParams sheetName
deptExportMap.put("title", deptExportParams);
//
deptExportMap.put("entity", LoginCaseDto.class);
// sheet
deptExportMap.put("data", objects[0]);
ExportParams empExportParams = new ExportParams();
empExportParams.setTitle(" RUL ");
empExportParams.setSheetName(" url");
// sheet2 map
Map<String, Object> empExportMap = new HashMap<>();
empExportMap.put("title", empExportParams);
empExportMap.put("entity", LoginUrlDto.class);
empExportMap.put("data", objects[1]);
// sheet1、sheet2 map
List<Map<String, Object>> sheetsList = new ArrayList<>();
sheetsList.add(deptExportMap);
sheetsList.add(empExportMap);
//
workBook = EasyPoiUtil.exportExcel(sheetsList, ExcelType.HSSF);
//String fileName = URLEncoder.encode("test", "UTF-8");
String filepath = (String) LoadStaticConfigUtil.getCommonYml( "testcaseexcel.cases");
FileOutputStream fos = new FileOutputStream(filepath);
workBook.write(fos);
fos.close();
}catch (Exception e){
e.printStackTrace();
}finally {
if(workBook != null) {
try {
workBook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "success";
}
마지막 으로 새로운 테스트 결과 표를 얻 을 수 있 습 니 다.프로젝트 원본 주소 전송 문
자바 에서 Easypoi 가 엑셀 다 중 sheet 표 가 져 오기 내 보 내기 기능 을 실현 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 Easypoi 엑셀 다 중 sheet 표 가 져 오기 내 보 내기 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java/Excel에 아래 첨자 및 위 첨자 삽입위 첨자 및 아래 첨자는 기준선 위 또는 아래에 입력되는 소문자 또는 숫자입니다. 일반적으로 각주, 참조, 수학 및 화학 기호에 사용됩니다. 이 기사에서는 Java용 Free Spire.XLS를 사용하여 프로그래밍 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.