Skip to content

Commit 7e909fb

Browse files
committed
별도목차파일 생성여부 선택 기능 추가
1 parent 648fbdb commit 7e909fb

File tree

5 files changed

+99
-13
lines changed

5 files changed

+99
-13
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<queries>
2+
<excel db="sampleDB" output="output/매출집계_2024_목차없음.xlsx" separateToc="false">
3+
<header>
4+
<font name="맑은 고딕" size="12" color="FFFFFF" bold="true"/>
5+
<fill color="4F81BD"/>
6+
<colwidths min="20" max="50"/>
7+
<alignment horizontal="center" vertical="middle"/>
8+
<border>
9+
<all style="thin" color="000000"/>
10+
</border>
11+
</header>
12+
<body>
13+
<font name="맑은 고딕" size="11" color="000000" bold="false"/>
14+
<fill color="FFFFCC"/>
15+
<alignment horizontal="left" vertical="middle"/>
16+
<border>
17+
<all style="thin" color="CCCCCC"/>
18+
</border>
19+
</body>
20+
</excel>
21+
<vars>
22+
<var name="startDate">2024-01-01</var>
23+
<var name="endDate">2024-06-30</var>
24+
<var name="regionList">'서울','부산'</var>
25+
</vars>
26+
<sheet name="주문_목록" use="true">
27+
<![CDATA[
28+
SELECT
29+
OrderNumber as 주문번호,
30+
FORMAT(OrderDate, 'yyyy-MM-dd') as 주문일,
31+
CustomerName as 고객명,
32+
ProductName as 상품명,
33+
Quantity as 수량,
34+
UnitPrice as 단가,
35+
(Quantity * UnitPrice) as 금액
36+
FROM OrderSummary
37+
WHERE OrderDate BETWEEN '${startDate}' AND '${endDate}'
38+
ORDER BY OrderDate DESC
39+
]]>
40+
</sheet>
41+
<sheet name="고객_목록" use="true">
42+
<![CDATA[
43+
SELECT
44+
CustomerID as 고객번호,
45+
CompanyName as 회사명,
46+
ContactName as 담당자,
47+
Country as 국가,
48+
City as 도시,
49+
Phone as 전화번호
50+
FROM Customer
51+
ORDER BY CompanyName
52+
]]>
53+
</sheet>
54+
<sheet name="주문_상세" use="true">
55+
<![CDATA[
56+
SELECT
57+
OrderDetailID as 상세번호,
58+
OrderID as 주문번호,
59+
ProductID as 상품번호,
60+
ProductName as 상품명,
61+
Quantity as 수량,
62+
UnitPrice as 단가,
63+
(Quantity * UnitPrice) as 라인합계
64+
FROM OrderDetail od
65+
INNER JOIN Product p ON od.ProductID = p.ProductID
66+
ORDER BY OrderID, ProductID
67+
]]>
68+
</sheet>
69+
</queries>

resources/queries-sample-long.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<queries db="sampleDB" output="output/매출집계_긴시트명테스트_${year}.xlsx">
2+
<queries db="sampleDB" output="output/매출집계_긴시트명테스트_${year}.xlsx" separateToc="true">
33
<variables>
44
<var name="year">2024</var>
55
</variables>

resources/queries-sample-orders.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"excel": {
33
"db": "sampleDB",
44
"output": "output/주문관리_보고서.xlsx",
5+
"separateToc": false,
56
"header": {
67
"font": { "name": "맑은 고딕", "size": 12, "color": "FFFFFF", "bold": true },
78
"fill": { "color": "4F81BD" },

resources/queries-sample.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<queries>
2-
<excel db="sampleDB" output="d:\temp/output/매출집계_2024.xlsx">
2+
<excel db="sampleDB" output="output/매출집계_2024.xlsx" separateToc="false">
33
<header>
44
<font name="맑은 고딕" size="12" color="FFFFFF" bold="true"/>
55
<fill color="4F81BD"/>

src/index.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,28 @@ async function main() {
184184
// CLI 변수 > 파일 전역변수 우선 적용
185185
const mergedVars = { ...globalVars, ...cliVars };
186186

187-
// 엑셀 전체 스타일 파싱 및 db/output 우선 적용
187+
// 기본값 설정
188188
let excelStyle = {};
189189
let excelDb = undefined;
190190
let excelOutput = undefined;
191+
let createSeparateToc = false; // 별도 목차 파일 생성 여부
192+
191193
if (argv.xml && fs.existsSync(resolvePath(argv.xml))) {
192194
const xml = fs.readFileSync(resolvePath(argv.xml), 'utf8');
193195
const parsed = await xml2js.parseStringPromise(xml, { trim: true });
196+
197+
// queries 루트 엘리먼트에서 separateToc 속성 확인
198+
if (parsed.queries && parsed.queries.$) {
199+
if (parsed.queries.$.separateToc) createSeparateToc = parsed.queries.$.separateToc === 'true';
200+
}
201+
194202
if (parsed.queries && parsed.queries.excel && parsed.queries.excel[0]) {
195203
const excel = parsed.queries.excel[0];
196204
if (excel.$ && excel.$.db) excelDb = excel.$.db;
197205
if (excel.$ && excel.$.output) excelOutput = excel.$.output;
206+
// excel 엘리먼트의 separateToc가 있으면 우선적용 (덮어쓰기)
207+
if (excel.$ && excel.$.separateToc) createSeparateToc = excel.$.separateToc === 'true';
208+
198209
excelStyle.header = {};
199210
excelStyle.body = {};
200211
if (excel.header && excel.header[0]) {
@@ -227,6 +238,7 @@ async function main() {
227238
excelStyle = queries.excel;
228239
if (queries.excel.db) excelDb = queries.excel.db;
229240
if (queries.excel.output) excelOutput = queries.excel.output;
241+
if (queries.excel.separateToc !== undefined) createSeparateToc = queries.excel.separateToc;
230242
}
231243
}
232244

@@ -315,16 +327,20 @@ async function main() {
315327
excelStyleHelper.populateTableOfContents(tocSheet, createdSheetNames);
316328
console.log(`[목차] 시트 내용 생성 완료 (맨 왼쪽 위치)`);
317329

318-
// 별도 목차 엑셀 파일 생성
319-
const tocWb = new ExcelJS.Workbook();
320-
excelStyleHelper.createExternalTableOfContents(tocWb, createdSheetNames, outFile);
321-
322-
// 파일명: 기존 outFile 기준 _목차_yyyymmddhhmmss.xlsx
323-
const tocExt = path.extname(outFile);
324-
const tocBase = outFile.slice(0, -tocExt.length);
325-
const tocFile = `${tocBase}_목차_${getNowTimestampStr()}${tocExt}`;
326-
await tocWb.xlsx.writeFile(tocFile);
327-
console.log(`[목차] 별도 엑셀 파일 생성: ${tocFile}`);
330+
// 별도 목차 엑셀 파일 생성 (설정에 따라 조건부 생성)
331+
if (createSeparateToc) {
332+
const tocWb = new ExcelJS.Workbook();
333+
excelStyleHelper.createExternalTableOfContents(tocWb, createdSheetNames, outFile);
334+
335+
// 파일명: 기존 outFile 기준 _목차_yyyymmddhhmmss.xlsx
336+
const tocExt = path.extname(outFile);
337+
const tocBase = outFile.slice(0, -tocExt.length);
338+
const tocFile = `${tocBase}_목차_${getNowTimestampStr()}${tocExt}`;
339+
await tocWb.xlsx.writeFile(tocFile);
340+
console.log(`[목차] 별도 엑셀 파일 생성: ${tocFile}`);
341+
} else {
342+
console.log(`[목차] 별도 파일 생성 안함 (separateToc=false)`);
343+
}
328344
}
329345

330346
await workbook.xlsx.writeFile(outFile);

0 commit comments

Comments
 (0)