标签支持行为

此示例显示了标记在不同操作中的工作方式

以下行为会影响到标签: 如果剪切复制或者拖拽剪切这些行为发生了,标签的数据就会跟着单元格一起移动。 如果复制粘贴或者拖动填充这些行为发生了,那么标签的数据就会被复制。如果标签的数据类型是复杂的类型,那么这个复杂类型的数据就会被克隆。 当这些影响标签的动作发生后,这些动作是可以被撤销和恢复的。
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("tan"); sheet.setTag(4, 2, "Number tag"); sheet.getCell(4, 2).backColor("tan"); sheet.setTag(4, 1, {row: 12, column: 2}); sheet.getCell(4, 1).backColor("tan"); sheet.setTag(5, 2, new Date(Date.UTC(2014, 7, 12))); sheet.getCell(5, 2).backColor("tan"); 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 = ""; } else { document.getElementById('txtTag').value = JSON.stringify(tag); } }); sheet.resumePaint(); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.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:lavender;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: lavender; padding: 4px; } p span { display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }