Skip to content

Commit

Permalink
fix: excel로 열었을 때, csv 한글 깨짐 이슈 해결 (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks authored Oct 8, 2024
1 parent 4534081 commit 969e0b1
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;
import static org.sopt.makers.crew.main.entity.apply.enums.EnApplyStatus.*;

import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -150,7 +152,6 @@ public List<MeetingV2GetMeetingBannerResponseDto> getMeetingBanner() {
return getResponseDto(meetings, postMap, applies);
}


private List<Post> filterLatestPostsByMeetingId(List<Post> posts) {
return posts.stream()
.collect(Collectors.groupingBy(Post::getMeetingId,
Expand Down Expand Up @@ -384,9 +385,15 @@ private void deleteCsvFile(String filePath) {
private String createCsvFile(List<Apply> applies) {
String filePath = UUID.randomUUID() + ".csv";

try (CSVWriter writer = new CSVWriter(new FileWriter(filePath))) {
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
new FileOutputStream(filePath), StandardCharsets.UTF_8);
CSVWriter writer = new CSVWriter(outputStreamWriter)) {

// BOM 추가 (Excel에서 UTF-8 파일을 제대로 처리하기 위함)
outputStreamWriter.write("\uFEFF");

// CSV 파일의 헤더 정의
String[] header = {"이름", "최근 활동 파트", "최근 활동 기수", "전화번호", "신청 날짜 및 시간", "신청 내용", "신청 상태"};
String[] header = {"이름", "최근 활동 파트", "최근 활동 기수", "전화번호", "신청 날짜 및 시간", "신청 상태"};
writer.writeNext(header);

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
Expand All @@ -400,7 +407,6 @@ private String createCsvFile(List<Apply> applies) {
String.valueOf(activity.getGeneration()),
String.format("\"%s\"", user.getPhone()),
apply.getAppliedDate().format(formatter),
apply.getContent(),
apply.getStatus().getDescription()
};
writer.writeNext(data);
Expand Down

0 comments on commit 969e0b1

Please sign in to comment.