Actions

Tags in SpreadJS are affected when different actions are performed. See what happens when a cell with a tag on it, is copied and pasted or dragged and dropped.

The following actions will affect tags as follows: If a cut and paste or drag and drop action occurs, tag data will move with the cell. If a copy and paste or drag and fill action occurs, tag data will be copied. If the type of tag is a complex type, it will be cloned. Tag actions can be undone or redone after they are complete.
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(); // set drag fill type to CopyCells in order to demo tag will be copied spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.copyCells; sheet.setArray(3, 1, [["a", 1], ["b", 2], ["c", 3]]); sheet.setTag(3, 1, "Tag for 'a'"); sheet.getCell(3, 1).backColor("#E3E3E3"); sheet.setTag(4, 2, "Number tag"); sheet.getCell(4, 2).backColor("#E3E3E3"); sheet.setTag(4, 1, {row: 12, column: 2}); sheet.getCell(4, 1).backColor("#E3E3E3"); sheet.setTag(5, 2, new Date(Date.UTC(2014, 7, 12))); sheet.getCell(5, 2).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); } }); sheet.resumePaint(); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.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="txtTag">Selected Cell Tag: </label> <input type="text" id="txtTag" style="width: 200px" /> </div> <p style="background-color:#F4F8EB;padding: 4px;"> Select a cell, highlighted above, to get its cell tag using a custom string format. You can also copy and paste a cell with tag.<br /> Note: the defaultDragFillType is set to copyCells in this demo. </p> </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; } label { display: inline-block; margin-right: 6px; } input { padding: 4px; margin: 0 4px 4px 0; } p { background-color: #F4F8EB; padding: 4px; } p span { display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }