Skip to content

Commit a659cd6

Browse files
committed
각 시트별 스타일 적용 기능 추가
1 parent b8ecdb8 commit a659cd6

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

queries/queries-sample.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<queries>
2-
<excel db="sampleDB" output="d:/temp/매출집계_2024.xlsx" separateToc="false" maxRows="20">
2+
<excel db="sampleDB" output="d:/temp/매출집계_2024.xlsx" separateToc="false" maxRows="20" style="modern">
33
<!-- 스타일 템플릿 ID 지정 (기본값: default) -->
44
<!-- 사용 가능한 템플릿: default, modern, dark, colorful, minimal, business, premium -->
55
<!-- 필요시 개별 스타일 속성으로 덮어쓰기 가능 -->
@@ -27,7 +27,7 @@
2727
ORDER BY OrderDate DESC
2828
]]>
2929
</sheet>
30-
<sheet name="고객_목록" use="true" aggregateColumn="지역">
30+
<sheet name="고객_목록" use="true" aggregateColumn="지역" style="dark">
3131
<![CDATA[
3232
SELECT
3333
CustomerCode as 고객코드,

queries/queries-with-template.xml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<queries>
2-
<excel db="sampleDB" output="d:/temp/매출집계_템플릿_2024.xlsx" separateToc="false" maxRows="20">
3-
<!-- 스타일 템플릿 ID 지정 (기본값: default) -->
2+
<excel db="sampleDB" output="d:/temp/매출집계_템플릿_2024.xlsx" separateToc="false" maxRows="20" style="business">
3+
<!-- 전역 스타일 템플릿 ID (기본값: default) -->
4+
<!-- 시트별로 개별 스타일을 지정할 수 있음 -->
45
<!-- 사용 가능한 템플릿: default, modern, dark, colorful, minimal, business, premium -->
5-
<!-- 필요시 개별 스타일 속성으로 덮어쓰기 가능 -->
66
</excel>
77
<vars>
88
<var name="envType">운영</var>
@@ -13,7 +13,8 @@
1313
<var name="categoryIds">[1, 2, 3, 5]</var>
1414
<var name="maxRows">1000</var>
1515
</vars>
16-
<sheet name="${envType}_주문_목록" use="true" aggregateColumn="결제방법" maxRows="10" db="sampleDB">
16+
<sheet name="${envType}_주문_목록" use="true" aggregateColumn="결제방법" maxRows="10" db="sampleDB" style="modern">
17+
<!-- 시트별 개별 스타일: modern -->
1718
<![CDATA[
1819
SELECT
1920
OrderNumber as 주문번호,
@@ -28,6 +29,7 @@
2829
]]>
2930
</sheet>
3031
<sheet name="고객_목록" use="true" aggregateColumn="지역">
32+
<!-- 시트별 스타일 미지정: 전역 스타일(business) 사용 -->
3133
<![CDATA[
3234
SELECT
3335
CustomerCode as 고객코드,
@@ -42,4 +44,20 @@
4244
ORDER BY CreditLimit DESC
4345
]]>
4446
</sheet>
47+
<sheet name="상품_목록" use="true" aggregateColumn="카테고리" style="colorful">
48+
<!-- 시트별 개별 스타일: colorful -->
49+
<![CDATA[
50+
SELECT
51+
ProductID as 상품ID,
52+
ProductName as 상품명,
53+
CategoryName as 카테고리,
54+
FORMAT(UnitPrice, 'N0') as 단가,
55+
UnitsInStock as 재고수량,
56+
Discontinued as 단종여부
57+
FROM SampleDB.dbo.Products p
58+
INNER JOIN SampleDB.dbo.Categories c ON p.CategoryID = c.CategoryID
59+
WHERE p.CategoryID IN (${categoryIds})
60+
ORDER BY c.CategoryName, p.ProductName
61+
]]>
62+
</sheet>
4563
</queries>

src/index.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ async function loadQueriesFromXML(xmlPath) {
236236
maxRows: s.$.maxRows ? parseInt(s.$.maxRows) : null,
237237
db: s.$.db || null,
238238
queryRef: s.$.queryRef || null,
239+
style: s.$.style || null, // 시트별 스타일 추가
239240
query: query
240241
};
241242
});
@@ -441,16 +442,16 @@ async function main() {
441442
let createSeparateToc = false; // 별도 목차 파일 생성 여부
442443
let globalMaxRows = null; // 전역 최대 조회 건수
443444

444-
// 스타일 템플릿 적용
445+
// 기본 스타일 템플릿 적용 (CLI 옵션)
445446
const selectedStyle = await getStyleById(argv.style);
446447
if (selectedStyle) {
447-
console.log(`🎨 적용된 스타일: ${selectedStyle.name} (${selectedStyle.description})`);
448+
console.log(`🎨 CLI에서 지정된 스타일: ${selectedStyle.name} (${selectedStyle.description})`);
448449
excelStyle = {
449450
header: selectedStyle.header || {},
450451
body: selectedStyle.body || {}
451452
};
452453
} else {
453-
console.warn(`⚠️ 스타일 템플릿을 찾을 수 없습니다: ${argv.style}`);
454+
console.warn(`⚠️ CLI에서 지정된 스타일 템플릿을 찾을 수 없습니다: ${argv.style}`);
454455
console.warn(` 💡 기본 스타일을 사용합니다.`);
455456
}
456457

@@ -479,6 +480,20 @@ async function main() {
479480
if (excel.$ && excel.$.separateToc) createSeparateToc = excel.$.separateToc === 'true';
480481
// excel 엘리먼트의 maxRows 읽기
481482
if (excel.$ && excel.$.maxRows) globalMaxRows = parseInt(excel.$.maxRows);
483+
// XML에서 스타일 템플릿 ID 읽기 (CLI 옵션보다 우선)
484+
if (excel.$ && excel.$.style) {
485+
const xmlStyleId = excel.$.style;
486+
const xmlStyle = await getStyleById(xmlStyleId);
487+
if (xmlStyle) {
488+
console.log(`🎨 XML에서 지정된 스타일: ${xmlStyle.name} (${xmlStyle.description})`);
489+
excelStyle = {
490+
header: xmlStyle.header || {},
491+
body: xmlStyle.body || {}
492+
};
493+
} else {
494+
console.warn(`⚠️ XML에서 지정된 스타일을 찾을 수 없습니다: ${xmlStyleId}`);
495+
}
496+
}
482497

483498
// XML에서 스타일 속성이 있으면 템플릿 스타일을 덮어씀
484499
if (excel.header && excel.header[0]) {
@@ -650,8 +665,27 @@ async function main() {
650665
}
651666

652667
if (recordCount > 0) {
668+
// 시트별 스타일 적용 (우선순위: 시트별 > XML 전역 > CLI > 기본)
669+
let sheetStyle = excelStyle; // 기본값은 전역 스타일
670+
671+
if (sheetDef.style) {
672+
const sheetStyleTemplate = await getStyleById(sheetDef.style);
673+
if (sheetStyleTemplate) {
674+
console.log(`\t🎨 시트별 스타일 적용: ${sheetStyleTemplate.name} (${sheetStyleTemplate.description})`);
675+
sheetStyle = {
676+
header: sheetStyleTemplate.header || {},
677+
body: sheetStyleTemplate.body || {}
678+
};
679+
} else {
680+
console.warn(`\t⚠️ 시트별 스타일을 찾을 수 없습니다: ${sheetDef.style}`);
681+
console.warn(`\t 💡 전역 스타일을 사용합니다.`);
682+
}
683+
} else {
684+
console.log(`\t🎨 전역 스타일 적용: ${excelStyle.header?.font?.name || '기본'} 스타일`);
685+
}
686+
653687
// 데이터와 스타일 적용 (1행부터 시작)
654-
excelStyleHelper.applySheetStyle(sheet, result.recordset, excelStyle, 1);
688+
excelStyleHelper.applySheetStyle(sheet, result.recordset, sheetStyle, 1);
655689

656690
// 데이터 추가 후 맨 앞에 DB 정보 행 삽입
657691
sheet.spliceRows(1, 0, [`📊 출처: ${sheetDbKey} DB`]);

0 commit comments

Comments
 (0)