CelperJAVA에서 Excel를 다룰 때 불편함을 해소하고자 합니다.

CelperJAVA에서 Excel을 다룰 때 "@" Annotation 제공합니다.**

qrcode_github.com.png

Untitled

1. 매핑 지원 : 더 이상 model → sheet || sheet → model의 기능을 구현하지 마세요.

2. setter가 아닌 간결한 Annotation을 사용해보세요.

**3. Fluent Style Code :

긴 코드로 인한 `"어디가 잘못된거지?"`경험하지 마세요.**

4. 손쉽게 스프레드시트와 셀의 스타일을 지정하세요.


기존 코드 사용celper 사용 코드 비교

public class OriginalExcelService {

    private String[] header =
            {"이름", "주소", "나이", "연락처",
                    "생년월일", "성별", "군필여부", "학적",
                    "국적", "전공", "학번", "학년", "학점",
                    "취업여부", "기숙사신청", "장애 학생", "val1",
                    "val2", "val3", "val4", "val5",
                    "val6", "val7", "val8", "val9",
                    "val10", "val11", "val12", "val13", "val14"
            };
    public Workbook load(List<Student> model) {
        Workbook workbook = new SXSSFWorkbook();
        // 엑셀 오브젝트 내에 시트 생성
        Sheet sheet = workbook.createSheet();

        // 헤더에 삽입
        int rowIndex = 0;
        Row headerRow = sheet.createRow(rowIndex++);
        for (int i = 0; i < header.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(header[i]);
        }

        // 바디에 데이터 삽입
        for (Student student : model) {
            Row bodyRow = sheet.createRow(rowIndex++);
            for (int i = 0; i < header.length; i++) {
                bodyRow.createCell(i);
            }
            setValues(bodyRow, student);
            setCellStyle();
        }

        return workbook;
    }

    void setValues(Row row, Student student){
        row.getCell(0).setCellValue(student.getName());
        row.getCell(1).setCellValue(student.getAddress());
        row.getCell(2).setCellValue(student.getAge());
        row.getCell(3).setCellValue(student.getPhoneNumber());
        row.getCell(4).setCellValue(student.getDateBirth());
        row.getCell(5).setCellValue(student.getGender().toSring());
				... 30개의 필드에 해당하는 작업
				... row.getCell and student.getXXX and setCellValue
    }
		// 30개의 필드에 해당하는 작업들..
    void setCellStyle(){}
    void validate(){}
    void setDefaultValue(){}
}
public class ExcelService {
    public ExcelWorkBook load(List<Student> model){
        ExcelWorkBook excelWorkBook = new ExcelWorkBook(WorkBookType.SXSSF);
        excelWorkBook.createSheet().modelToSheet(model);
        return excelWorkBook;
    }
}
@SheetStyle(StudentSheetStyle.class)
public class Student {

    @Column("이름")
    @CellFormat(customFormat = "@ 학생")
    @ColumnStyle(dataAreaStyle = EmphasizeCellStyle.class, headerAreaStyle = EmphasizeCellStyle.class)
    private String name;

    @Column("주소")
    @CellFormat(customFormat = "@ (행정코드)")
    private String address;

    @Column("나이")
    @CellFormat(customFormat = "# 세 (만)")
    private int age;

    @Column("연락처")
    @CellFormat(customFormat = "@ - @ - @")
    private String phoneNumber;

    @Column("생년월일")
    @CellFormat(builtinFormat = BuiltinCellFormatType.SIMPLE_DATE)
    private LocalDate dateBirth;

    @Column("성별")
    private Gender gender;

		... 30개 필드
}