

Notionμμ Internal Integrationμ μμ±ν΄
Secret Token = νλΌμ΄λΉ API ν΅ν© μν¬λ¦Ώ λ°κΈ (μν¬μ€νμ΄μ€ μμ±μλ§ κ°λ₯)
ν ν°μ ntn_ μΌλ‘ μμ

μ΄ ν ν°μ ν΅ν©μ 곡μ λ νμ΄μ§/DBλ§ μ κ·Ό κ°λ₯
ν ν° μμ± μ£Όμ
?v= λ€μ μμ IDλ₯Ό μ¬μ©xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)κ° νμ.24ed5864-227a-8032-b957-fdc14deca543
- μ 무 λ΄μ©: Title(νμ΄μ§ μ λͺ©)
- μν: Status νμ (μ¬μ μ μλ μ΅μ μ¬μ©)
- ννΈ: Multi-select(κΈ°ν/λμμΈ/νλ‘ νΈμλ/λ°±μλ λ±)
- λ΄λΉμ: People
- μμ λ μ§: Date(μμ~μ’ λ£ λ²μ μ¬μ©)

'NOTION_TOKEN': notion scret token => ntnμΌλ‘ μμνλ κ²
'NOTION_DATABASE_TOKEN': νμ΄νμ΄ ν¬ν¨λ μ£Όμ
function getNotionDataWBSWithDates() {
const token = 'NOTION_TOKEN';
const databaseId = 'NOTION_DATABASE_TOKEN';
const url = `https://api.notion.com/v1/databases/${databaseId}/query`;
const options = {
method: 'post',
headers: {
'Authorization': `Bearer ${token}`,
'Notion-Version': '2022-06-28',
'Content-Type': 'application/json'
}
};
const response = UrlFetchApp.fetch(url, options);
const data = JSON.parse(response.getContentText());
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('μνΈ1');
// ==== μνΈ μ΄κΈ°ν ====
sheet.getRange(1,1,sheet.getMaxRows(), sheet.getMaxColumns()).breakApart();
sheet.clearContents();
sheet.clearFormats();
// ==== κΈ°λ³Έ WBS μ΄ μμ± ====
const headers = ['ꡬλΆ', 'μ
무 λ΄μ©', 'μν', 'ννΈ', 'λ΄λΉμ'];
// μ΄κ±΄ λ
Έμ
μμ μμ±ν dbμ μ΄λ¦κ³Ό λκ°μμΌν©λλ€!
const startDate = new Date("2025-09-29");
const endDate = new Date("2025-11-29");
// λ μ§ ν€λ μμ±
const dateHeaders = [];
let currentDate = new Date(startDate);
while(currentDate <= endDate){
dateHeaders.push(`${currentDate.getMonth()+1}μ ${currentDate.getDate()}μΌ`);
currentDate.setDate(currentDate.getDate() + 1);
}
// ν€λ κ° μ€μ
sheet.getRange(1, 1, 1, headers.length + dateHeaders.length).setValues([headers.concat(dateHeaders)]);
sheet.getRange(1,1,1,headers.length + dateHeaders.length).setBackground('#D9D9D9');
sheet.getRange(1,1,1,headers.length + dateHeaders.length).setFontWeight('bold');
sheet.getRange(1,1,1,headers.length + dateHeaders.length).setHorizontalAlignment('center');
// λ μ§ ν€λ ν°νΈ ν¬κΈ° μ€μ΄κΈ°
sheet.getRange(1, headers.length + 1, 1, dateHeaders.length).setFontSize(8);
// μ΄ λλΉ μ§μ
sheet.setColumnWidth(1, 100); // ꡬλΆ
sheet.setColumnWidth(2, 300); // μ
무 λ΄μ©
sheet.setColumnWidth(3, 100); // μν
sheet.setColumnWidth(4, 120); // ννΈ
sheet.setColumnWidth(5, 150); // λ΄λΉμ
for(let i=0;i<dateHeaders.length;i++){
sheet.setColumnWidth(headers.length + i + 1, 50); // λ μ§ μ΄ λλΉ κ³ μ
}
// ==== λ΄λΉμ μ΄λ¦ λ§€ν ====
const assigneeMap = {
'λ΄λΉμ λ
Έμ
μ΄λ¦': 'WBSμ μ
λ ₯λ μ΄λ¦',
};
// ==== κ΅¬λΆ ν€μλ ====
const sections = ['κΈ°ν λ° μ€κ³', 'λμμΈ', 'κ°λ°'];
let row = 2;
sections.forEach(section => {
const sectionStartRow = row;
const filtered = data.results.filter(page => {
const partArray = page.properties['ννΈ']?.multi_select?.map(p => p.name) || [];
const start = page.properties['μμ
λ μ§']?.date?.start;
if (!start) return false; // λ μ§ μλ νλͺ© μ μΈ
if(section === 'κΈ°ν λ° μ€κ³') return partArray.includes('κΈ°ν');
if(section === 'λμμΈ') return partArray.includes('λμμΈ');
if(section === 'κ°λ°') return partArray.some(p => ['νλ‘ νΈμλ','λ°±μλ'].includes(p));
return false;
});
filtered.forEach(page => {
const properties = page.properties;
const task = properties['μ
무 λ΄μ©']?.title[0]?.plain_text || '';
const status = properties['μν']?.status?.name || '';
let part = properties['ννΈ']?.multi_select?.map(p => p.name).join(', ') || '';
// λ΄λΉμ μ΄λ¦ λ³ν
let assignees = '';
if(properties['λ΄λΉμ']?.people){
assignees = properties['λ΄λΉμ'].people
.map(p => assigneeMap[p.name] || p.name)
.join(', ');
}
// μμ
λ μ§ λ²μ
const start = properties['μμ
λ μ§']?.date?.start;
const end = properties['μμ
λ μ§']?.date?.end;
let workDates = [];
if(start){
let s = new Date(start);
let e = end ? new Date(end) : new Date(start);
if(e < s) e = new Date(start); // start > end λ°©μ§
while(s <= e){
workDates.push(`${s.getMonth()+1}μ ${s.getDate()}μΌ`);
s.setDate(s.getDate() + 1);
}
}
// ν μμ±
sheet.getRange(row,1,1,headers.length).setValues([[section, task, status, part, assignees]]);
sheet.getRange(row,1,1,headers.length).setBackground('#FFFFFF'); // κΈ°λ³Έ ν°μ
// μμ
λ μ§ μμΉ
const sectionColor = section === 'κΈ°ν λ° μ€κ³' ? '#FFC7C7' :
section === 'λμμΈ' ? '#C7D9FF' :
'#FFFAC7'; // κ°λ°
workDates.forEach(d => {
const dateCol = headers.length + dateHeaders.indexOf(d) + 1;
if(dateCol > headers.length){
sheet.getRange(row,dateCol).setBackground(sectionColor);
}
});
row++; // ν ν μ¦κ°
});
const sectionEndRow = row - 1;
if(sectionEndRow >= sectionStartRow){
sheet.getRange(sectionStartRow,1,sectionEndRow-sectionStartRow+1,1).merge();
sheet.getRange(sectionStartRow,1).setValue(section);
sheet.getRange(sectionStartRow,1,sectionEndRow-sectionStartRow+1,1).setBackground('#D9D9D9');
sheet.getRange(sectionStartRow,1,sectionEndRow-sectionStartRow+1,1).setFontWeight('bold');
sheet.getRange(sectionStartRow,1,sectionEndRow-sectionStartRow+1,1).setHorizontalAlignment('center');
}
});
}


μ€νν¨μ : μ€ν¬λ¦½νΈ ν¨μ μ΄λ¦μ΄λ²€νΈ μμ€μ ν : μκ°κΈ°λ°μκ° μ ν μ ν: ν μν©μ λ§κ² μ νλΆ κ°κ²© μ ν: ν μν©μ λ§κ² μ ν