자동 확장

이 샘플에서는 UI 작업을 사용하여 표 범위를 자동 확장하는 방법을 보여 줍니다. 예를 들어 셀 E5(‘Sales Manager’)를 클릭한 다음, TAB 키를 누릅니다. 새 행이 자동으로 추가됩니다. 추가 옵션에 대해서는 아래 설명을 참조하십시오.

사용자는 데이터를 추가하거나 복사하여 붙여넣기, 끌어서 채우기 및 끌어서 놓기 작업을 사용하여 표 범위를 자동으로 확장할 수 있습니다. 작업에 따라 새 표 열이 표 오른쪽에 삽입되거나 새 표 행이 마지막 행 아래에 추가됩니다.   1. 표 열 바로 오른쪽 또는 마지막 표 행 바로 뒤에 데이터를 추가합니다.   2. 현재 표 범위를 초과하는 데이터를 붙여넣습니다.   3. 표 범위에서 끌어서 채웁니다.   4. 범위를 표 범위로 끌어서 놓습니다. allowAutoExpand을 사용하여 자동 확장 기능을 활성화/비활성화할 수 있습니다. 이 API를 통해 자동 확장 토글 상태를 가져올 수도 있습니다.
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); var spreadNS = GC.Spread.Sheets; var sheet = spread.getSheet(0); sheet.tables.add("table1", 1, 1, 4, 4, spreadNS.Tables.TableThemes.light1); _getElementById("allowAutoExpand").addEventListener('change', function() { var table = sheet.tables.all()[0]; if (table) { table.allowAutoExpand(_getElementById("allowAutoExpand").checked); } }); sheet.setColumnWidth(1, 120); sheet.setColumnWidth(2, 120); sheet.setColumnWidth(3, 120); sheet.setColumnWidth(4, 120); sheet.getCell(1, 1).text("First Name"); sheet.getCell(1, 2).text("Last Name"); sheet.getCell(1, 3).text("Score"); sheet.getCell(1, 4).text("Position"); sheet.getCell(2, 1).text("Alexa"); sheet.getCell(2, 2).text("Wilder"); sheet.getCell(2, 3).text("90"); sheet.getCell(2, 4).text("Web Developer"); sheet.getCell(3, 1).text("Victor"); sheet.getCell(3, 2).text("Wooten"); sheet.getCell(3, 3).text("70"); sheet.getCell(3, 4).text(".NET Developer"); sheet.getCell(4, 1).text("Ifeoma"); sheet.getCell(4, 2).text("Mays"); sheet.getCell(4, 3).text("85"); sheet.getCell(4, 4).text("Sales Manager"); spread.resumePaint(); } function _getElementById(id){ return document.getElementById(id); }
<!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>Select the table in the Spread instance and change the state of allow table auto expand.</p> <div class="option-group"> <input type="checkbox" id="allowAutoExpand" checked/> <label for="allowAutoExpand">Allow Table Auto Expand</label> </div> </div> </div></body> </html>
.sample { position: relative; height: 100%; overflow: auto; } .sample::after { display: block; content: ""; clear: both; } .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; } .option-group { margin-bottom: 6px; } label { display: inline-block; min-width: 90px; margin-bottom: 6px; } select { padding: 4px 6px; } p { padding: 0 0 12px; margin: 0; } .options-toggle { display: none; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }