addCustomName 메서드를 사용하여 다음과 같이 통합 문서 또는 워크시트에 이름을 추가합니다:
removeCustomName 메서드를 사용하여 다음과 같이 통합 문서 또는 워크시트에서 지정된 이름을 제거합니다:
clearCustomNames 메서드를 사용하여 다음과 같이 통합 문서 또는 워크시트에서 모든 이름을 제거합니다:
사용자 정의 NameInfo 클래스에는 다음과 같이 통합 문서 또는 워크시트의 이름, 표현식, 행, 열 및 메모 속성이 포함됩니다:
SpreadJS는 사용자 정의 NameInfo 업데이트를 지원합니다. 다음을 포함합니다.
사용자 정의 이름 바꾸기 및 참조된 모든 수식 업데이트
사용자 정의 이름의 수식 변경
사용자 정의 이름에 대한 설명 업데이트
window.onload = initFunction;
function initFunction() {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 1});
spread.suspendPaint();
var sheet = spread.getActiveSheet();
sheet.setColumnWidth(1, 100);
sheet.setValue(2, 1, "Sample scope:");
sheet.setValue(2, 2, 1);
sheet.setValue(2, 3, 2);
sheet.setValue(3, 2, 3);
sheet.setValue(3, 3, 4);
// add custom name
sheet.addCustomName("customName1", "=$B$3", 0, 0, "this is a customName!");
sheet.setFormula(5, 1, "=customName1");
sheet.addCustomName("customName2", "=$C$3:$D$4", 0, 0, "this is another customName!");
sheet.setFormula(5, 2, "=sum(customName2)");
printNames(sheet);
document.getElementById('setNameInfo').onclick = function () {
var sheet = spread.getActiveSheet();
var name = document.getElementById('setname').value;
if (name === '') {
alert("name should not be empty");
return;
}
var comment = document.getElementById('setComment').value;
var isReadOnly = document.getElementById('setIsReadOnly').checked;
var formula = GC.Spread.Sheets.CalcEngine.rangeToFormula(sheet.getSelections()[0], 0, 0, GC.Spread.Sheets.CalcEngine.RangeReferenceRelative.allAbsolute);
sheet.addCustomName(name, formula, 0, 0, comment, isReadOnly);
printNames(sheet);
};
function printNames(sheet) {
var namesInfo = sheet.getCustomNames();
var str = "name\t\treference\n";
namesInfo.forEach(function (nameInfo) {
var name = nameInfo.getName();
var reference = GC.Spread.Sheets.CalcEngine.rangeToFormula(nameInfo.getExpression().getRange());
str += name + " " + reference + '\n';
});
document.getElementById('allNameInfo').value = str;
}
sheet.bind(GC.Spread.Sheets.Events.CellClick, function (sender, args) {
var sheet = args.sheet;
var selection = sheet.getSelections()[0];
document.getElementById('setname').value = '';
document.getElementById('setComment').value = '';
document.getElementById('setIsReadOnly').checked = false;
document.getElementById('reference').value = GC.Spread.Sheets.CalcEngine.rangeToFormula(selection);
var customNames = sheet.getCustomNames();
for (var i = 0; i < customNames.length; i++) {
var customName = customNames[i];
var range = customName.getExpression().getRange();
if (range.row === selection.row && range.col === selection.col
&& range.rowCount === selection.rowCount && range.colCount === selection.colCount) {
var name = customName.getName();
var comment = customName.getComment();
var isReadOnly = customName.isReadOnly();
document.getElementById('setname').value = name;
document.getElementById('setComment').value = comment;
document.getElementById('setIsReadOnly').checked = !!isReadOnly;
break;
}
}
});
spread.resumePaint();
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta name="spreadjs culture" content="ko-kr"/>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ko/purejs/node_modules/@mescius/spread-sheets-resources-ko/dist/gc.spread.sheets.resources.ko.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<strong class="sp-demo-HeaderTitle">Settings:</strong>
<p style="padding:2px 10px">Select a range to add custom name.</p>
<div id="settingsDiv" style="margin-top: 10px">
<div class="option-row">
<label for="setName">Name:</label>
<input type="text" id="setname" placeholder="Name should not be empty"/>
</div>
<div class="option-row">
<label for="setComment">Comment:</label>
<input type="text" id="setComment"/>
</div>
<div class="option-row">
<label for="setIsReadOnly">IsReadOnly:</label>
<input type="checkbox" id="setIsReadOnly" />
</div>
<div class="option-row">
<label for="reference">Reference:</label>
<input type="text" id="reference"/>
</div>
<div class="option-row">
<input type="button" id="setNameInfo" value="Add Custom Name" style="width:125px; margin-left: 10px"/>
</div>
<div class="option-row">
<label for="reference">All CustomNames:</label>
<textarea rows="5" cols="30" id="allNameInfo"></textarea>
</div>
</div>
</div>
</div></body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
}
input {
display:block;
width: 100%;
margin: 8px 0;
box-sizing: border-box;
}
input[type=checkbox] {
display: inline-block;
width: initial;
margin: 0;
vertical-align: middle;
}
label, input {
padding: 4px 6px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}