指示符

此示例显示如何自定义注释指示符颜色和指示符大小。

在添加注释之前,可以使用indicatorSize方法设置注释的指示符大小,或者使用indicatorColor方法设置注释的指示符颜色。 例如: 您还可以获取注释指示符的大小和颜色 您应在合法范围内设置尺寸和颜色: 如果要设置指示符颜色,则应设置string类型数据。 如果无法将该字符串标识为颜色(例如可以标识“黑色”,“#000”,“ rgba(255、255、0、0.5)”),则注释指示符将设置为默认颜色black 。 如果要设置指示符大小,则应设置number类型数据,并确保数据> 1。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook($("ss")); var sheet = spread.getActiveSheet(); initData(); $('setColor').addEventListener('click', function () { var color = $('color').value; var comments = sheet.comments.get(1, 1); if (!comments) { initData(); } sheet.comments.get(1, 1).indicatorColor(color); $('color').value = sheet.comments.get(1, 1).indicatorColor(); }); $('setSize').addEventListener('click', function () { var size = $('size').value; var comments = sheet.comments.get(1, 1); if (!comments) { initData(); } sheet.comments.get(1, 1).indicatorSize(Number(size)); $('size').value = sheet.comments.get(1, 1).indicatorSize(); }); function initData() { sheet.addSpan(1, 1, 1, 6); sheet.setValue(1, 1, "there is a comment on the upper right corner of the cell"); sheet.comments.add(1, 1, "new comment!"); $('color').value = sheet.comments.get(1, 1).indicatorColor(); $('size').value = sheet.comments.get(1, 1).indicatorSize(); } }; function $(id) { return document.getElementById(id); }
<!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" /> <meta name="spreadjs culture" content="zh-cn" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/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 style="float: right;"> <!-- change indicator options --> <div class="group"> <div> <div></div> <div> <div> <label for="color">Color</label> <input id="color" class="form-control"> <input type="button" id="setColor" value="Set Comment Indicator Color" class="option-row"> </div> </div> <div class="col-sm-12" style="height: 30px;"></div> <div class="col-sm-12"> <div class="input-group"> <label for="size">Size</label> <input id="size" class="form-control"> <input type="button" id="setSize" value="Set Comment Indicator Size" class="option-row"> </div> </div> <div class="col-sm-12" style="height: 30px;"></div> </div> </div> </div> </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; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .sample-options{ z-index: 1000; } .option { padding-bottom: 6px; } .checkbox { padding-right: 12px; display: inline-block; } label { display: inline-block; min-width: 100px; } input, select { width: 100%; padding: 4px 0; margin-top: 4px; box-sizing: border-box; } input[type=checkbox] { width: auto; padding: 0; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }