Skip to content

Commit 1d2c4a0

Browse files
committed
목차 시트 중복 생성 에러 수정
1 parent 1868876 commit 1d2c4a0

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/index.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ async function main() {
329329
}
330330
}
331331

332-
// 목차 시트 추가
333-
if (createdSheetNames.length > 0) {
334-
const tocSheet = workbook.addWorksheet('목차');
332+
// 목차 시트에 내용 채우기
333+
if (createdSheetNames.length > 0 && tocSheet) {
334+
// 이미 생성된 목차 시트에 내용 추가
335335
tocSheet.addRow(['No', 'Sheet Name', 'Data Count']);
336336
createdSheetNames.forEach((obj, idx) => {
337337
const row = tocSheet.addRow([idx + 1, obj.displayName, createdSheetCounts[idx]]);
@@ -358,26 +358,29 @@ async function main() {
358358
{ header: 'Data Count', key: 'count', width: 12 }
359359
];
360360

361-
// 별도 목차 엑셀 파일 생성
362-
const tocWb = new ExcelJS.Workbook();
363-
const tocOnly = tocWb.addWorksheet('목차');
364-
tocOnly.addRow(['No', 'Sheet Name', 'Data Count']);
365-
createdSheetNames.forEach((obj, idx) => {
366-
const row = tocOnly.addRow([idx + 1, obj.displayName, createdSheetCounts[idx]]);
367-
row.getCell(2).font = { color: { argb: '0563C1' }, underline: true };
368-
row.getCell(3).font = { color: { argb: '0563C1' }, underline: true };
369-
});
370-
tocOnly.getRow(1).font = { bold: true };
371-
tocOnly.columns = [
372-
{ header: 'No', key: 'no', width: 6 },
373-
{ header: 'Sheet Name', key: 'name', width: 30 },
374-
{ header: 'Data Count', key: 'count', width: 12 }
375-
];
376-
const tocExt = path.extname(outFile);
377-
const tocBase = outFile.slice(0, -tocExt.length);
378-
const tocFile = `${tocBase}_목차_${getNowTimestampStr()}${tocExt}`;
379-
await tocWb.xlsx.writeFile(tocFile);
380-
console.log(`[목차] 별도 엑셀 파일 생성: ${tocFile}`);
361+
if (createSeparateToc) {
362+
// 별도 목차 엑셀 파일 생성
363+
const tocWb = new ExcelJS.Workbook();
364+
const tocOnly = tocWb.addWorksheet('목차');
365+
tocOnly.addRow(['No', 'Sheet Name', 'Data Count']);
366+
createdSheetNames.forEach((obj, idx) => {
367+
const row = tocOnly.addRow([idx + 1, obj.displayName, createdSheetCounts[idx]]);
368+
row.getCell(2).font = { color: { argb: '0563C1' }, underline: true };
369+
row.getCell(3).font = { color: { argb: '0563C1' }, underline: true };
370+
});
371+
tocOnly.getRow(1).font = { bold: true };
372+
tocOnly.columns = [
373+
{ header: 'No', key: 'no', width: 6 },
374+
{ header: 'Sheet Name', key: 'name', width: 30 },
375+
{ header: 'Data Count', key: 'count', width: 12 }
376+
];
377+
const tocExt = path.extname(outFile);
378+
const tocBase = outFile.slice(0, -tocExt.length);
379+
const tocFile = `${tocBase}_목차_${getNowTimestampStr()}${tocExt}`;
380+
await tocWb.xlsx.writeFile(tocFile);
381+
console.log(`[목차] 별도 엑셀 파일 생성: ${tocFile}`);
382+
}
383+
381384
}
382385
console.log(`\nGenerating excel file ... `);
383386
console.log(`Wating a few seconds ... `);

0 commit comments

Comments
 (0)