Execel JS \n 적용 시키는 법
먼저 cell을 쉽게 생성하기 위한 함수를 만들었습니다.
ts
import ExcelJS from 'exceljs';
export default function ExcelText(
worksheet: ExcelJS.Worksheet,
cell: string,
text: string,
fontSize: number,
vertical: any,
horizontal: any,
color: string = '',
bold: boolean = false,
) {
const cellRef = worksheet.getCell(cell);
// 텍스트 추가
cellRef.value = {
richText: [
{
text: text,
font: { size: fontSize, bold, color: { argb: color } },
},
],
};
// 스타일 적용
cellRef.alignment = { vertical, horizontal };
}이후 cell의 줄 바꿈을 적용시키기 위해서는 특정 효과를 적용시켜야 합니다.
js
ExcelText(
worksheet,
`F${40 + itemLength}`,
`3F, HANDOK BLDG., 2645, NAMBUSUNHWAN-RO, \nGANGNAM-GU, SEOUL, 06271, SOUTH KOREA`,
10,
'middle',
'left',
'',
);
worksheet.getCell(`E${40 + itemLength}`).alignment = { wrapText: true };- #execelJs
- #\N