지정한 셀의 값을 가져오거나 설정할 수 있습니다.
값 계열을 가져오거나 셀 범위에 값을 설정하려면 다음과 유사한 코드를 사용할 수 있습니다.
지정된 셀에 텍스트를 가져오거나 설정할 수도 있습니다. 이는 셀에 값을 가져오거나 설정하는 것과 유사합니다.
데이터를 삭제하려면 다음 메서드를 사용하여 지정된 범위의 데이터를 지울 수 있습니다.
SpreadJS는 한 범위에서 다른 범위로 데이터 계열을 복사하거나 이동하는 기능도 지원합니다.
sheet.options.showZeros 옵션을 사용하여 셀에 0 값을 표시할지 여부를 제어할 수 있습니다. false인 경우 0 값이 있는 셀은 숫자 0을 표시하는 대신 공백으로 표시됩니다.
window.onload = function() {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'));
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getSheet(0);
sheet.suspendPaint();
sheet.setValue(1, 1, 'setValue');
sheet.setValue(1, 2, 2014);
sheet.setText(3, 1, 'setText');
sheet.setText(3, 2, '01/01/2014');
sheet.setText(5, 1, '0 Value');
sheet.setValue(5, 2, 0);
sheet.setColumnWidth(2, 90);
sheet.setColumnWidth(8, 120);
sheet.setColumnWidth(9, 120);
sheet.setValue(0, 7, 'setArray');
sheet.setArray(1, 7, [
[ 'ID', 'Phone Number', 'Address' ],
[ 1, '021-432378', 'Marbury Road' ],
[ 2, '021-432668', 'Chester Road' ],
[ 3, '021-432238', 'Gertt Road' ],
[ 4, '021-432533', 'Jnyliner Road' ],
[ 5, '021-432125', 'Approach Road' ],
[ 6, '021-432789', 'Jones Road' ]
]);
initStyle(sheet);
document.getElementById('btnCopy').addEventListener('click', function() {
sheet.copyTo(1, 7, 10, 7, 7, 3, spreadNS.CopyToOptions.all);
});
document.getElementById('btnMove').addEventListener('click', function() {
sheet.moveTo(0, 7, 9, 7, 8, 3, spreadNS.CopyToOptions.all);
});
document.getElementById('showZeros').addEventListener('change', function() {
spread.getActiveSheet().options.showZeros = this.checked;
});
sheet.resumePaint();
};
function initStyle (sheet) {
let style = new GC.Spread.Sheets.Style();
style.backColor = '#c6c0ca';
for (let row = 1; row < 6; row++) {
for (let col = 1; col < 3; col++) {
sheet.setStyle(row, col, style);
}
}
style = new GC.Spread.Sheets.Style();
style.backColor = '#bbd2cc';
for (let row = 1; row < 8; row++) {
for (let col = 7; col < 10; col++) {
sheet.setStyle(row, col, style);
}
}
style = new GC.Spread.Sheets.Style();
style.backColor = '#fcd8dd';
for (let row = 10; row < 17; row++) {
for (let col = 7; col < 10; col++) {
sheet.setStyle(row, col, style);
}
}
}
<!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">
<p>Users can set the data for the worksheet or get the data from the worksheet.</p>
<p>Clicking the "Copy" button will copy the data from H2:J8 to H11:J17.</p>
<p>Clicking the "Move" button will move the data from H1:J8 to H10:J17.</p>
<input type="button" value="Copy" id="btnCopy" />
<input type="button" value="Move" id="btnMove" />
<hr/>
<input type="checkbox" class="usedRange" id="showZeros" checked/>
<label for="showZeros" class="usedRange">Show Zero Value Cells</label>
</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;
margin-top: 10px;
}
label {
display: block;
margin-bottom: 6px;
margin-top: 6px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: inline-block;
width: 85px;
}
.usedRange {
display: inline-block;
}
#btnCopy {
margin-right: 40px;
}
#data-used-range {
margin-left: 75px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}