검색

문자열 유형인 셀 태그를 검색할 수 있습니다. 검색 순서는 zOrder(열 우선) 또는 nOrder(행 우선)로 설정할 수 있습니다.

SearchCondition을 준비한 다음 검색 태그에 대해 searchTarget을 SearchFoundFlags.cellTag로 설정합니다. sheet.search(searchCondition)를 사용하여 검색을 수행합니다. 검색 결과의 foundRowIndex 및 foundColumnIndex 첫 번째로 일치한 셀 위치를 제공합니다. 발견되지 않으면 둘 다 -1입니다.
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 1}); initSpread(spread); }; function initSpread(spread) { var spreadNS = GC.Spread.Sheets, sheet = spread.sheets[0]; sheet.suspendPaint(); // add tags for demo use sheet.getCell(0, 0).tag("A1 tag"); sheet.getCell(1, 6).tag("demo tag for G2"); sheet.setTag(3, 1, "B4 tag demo"); sheet.getCell(0, 0).backColor("#E3E3E3"); sheet.getCell(1, 6).backColor("#E3E3E3"); sheet.getCell(3, 1).backColor("#E3E3E3"); var r, c; for (r = 7; r <= 10; r++) { for (c = 0; c <= 2; c++) { sheet.setTag(r, c, "Cell tag " + String.fromCharCode(65 + c) + (r + 1)); sheet.getCell(r, c).backColor("#E3E3E3"); } } for (r = 5; r <= 8; r++) { for (c = 5; c <= 7; c++) { sheet.setTag(r, c, "demo tag " + String.fromCharCode(65 + c) + (r + 1)); sheet.getCell(r, c).backColor("#E3E3E3"); } } sheet.bind(spreadNS.Events.EnterCell, function () { var tag = sheet.getTag(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (tag == null) { document.getElementById('txtTag').value = ''; } else if (typeof tag === "string") { document.getElementById('txtTag').value = tag; } else { document.getElementById('txtTag').value = JSON.stringify(tag); } }); document.getElementById('btnSearchTag').onclick = function () { var searchOrder = parseInt(document.getElementById('searchOrder').value, 10); if (isNaN(searchOrder)) { return; } var condition = new spreadNS.Search.SearchCondition(); condition.searchTarget = spreadNS.Search.SearchFoundFlags.cellTag; condition.searchString = document.getElementById('txtSearchTag').value; condition.findBeginRow = sheet.getActiveRowIndex(); condition.findBeginColumn = sheet.getActiveColumnIndex(); condition.searchOrder = searchOrder; if (searchOrder === 0) { condition.findBeginColumn++; } else { condition.findBeginRow++; } var result = sheet.search(condition); if (result.foundRowIndex < 0 && result.foundColumnIndex < 0) { condition.findBeginRow = 0; condition.findBeginColumn = 0; result = sheet.search(condition); } var row = result.foundRowIndex, col = result.foundColumnIndex; if (row < 0 && col < 0) { document.getElementById('txtTag').value = 'Not found'; } else { sheet.setActiveCell(row, col); document.getElementById('txtTag').value = sheet.getTag(row, col); } }; sheet.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"> <div class="option-row"> <label for="txtSearchTag">Search tag equals.</label> <label>For example enter: B4 tag demo (case sensitive):</label> <input type="text" id="txtSearchTag" placeholder="tag name" /> </div> <div class="option-row"> <label for="searchOrder">Search Order:</label> <select id="searchOrder"> <option value="0">Column First (ZOrder)</option> <option value="1">Row First (NOrder)</option> </select> <input type="button" id="btnSearchTag" value="Find Tag" title="Search cell with tag contains specified content and active the cell" /> </div> <div class="option-row"> <label for="txtTag" style="width:210px">Selected cell tag:</label> <input type="text" id="txtTag" /> </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; } .wide { width: 100%; box-sizing: border-box; } label { display: block; margin-bottom: 6px; } input, select { padding: 4px; margin: 0 4px 4px 0; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }