浮动对象元素事件

SpreadJS 在表单上提供了一些浮动对象元素相关的事件来让你更方便的监视浮动对象元素的变化。

<p>自定制浮动对象元素提供了两个事件: <strong>FloatingObjectSelectionChanged</strong> (浮动对象元素的选择状态发生变化后) 和 <strong>FloatingObjectChanged</strong> (浮动对象元素变化后)。</p> <pre><code class="hljs js language-js">sheet.bind(GC.Spread.Sheets.Events.FloatingObjectSelectionChanged, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e, args</span>) </span>{ <span class="hljs-comment">// do something</span> }); sheet.bind(GC.Spread.Sheets.Events.FloatingObjectChanged, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e, args</span>) </span>{ <span class="hljs-comment">// do something</span> }); </code></pre> <p>图片也提供了两个事件: <strong>PictureSelectionChanged</strong> (图片的选择状态发生变化后) and <strong>PictureChanged</strong> (图片变化后)</p> <pre><code class="hljs js language-js">sheet.bind(GC.Spread.Sheets.Events.PictureSelectionChanged, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e, args</span>) </span>{ <span class="hljs-comment">// do something</span> }); sheet.bind(GC.Spread.Sheets.Events.PictureChanged, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e, args</span>) </span>{ <span class="hljs-comment">// do something</span> }); </code></pre>
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var spreadNS = GC.Spread.Sheets; var sheet = spread.getSheet(0); sheet.suspendPaint(); var customFloatingObject = new spreadNS.FloatingObjects.FloatingObject("f1"); customFloatingObject.startRow(1); customFloatingObject.startColumn(1); customFloatingObject.endColumn(6); customFloatingObject.endRow(6); var div = document.createElement('div'); div.innerHTML = "<span>SpreadJS supports FloatingObject.</span><div style='border: 1px dotted red; width: 80%; margin:auto;'><ul><li>I am list one.</li><li>I am list two.</li><li>I am list three.</li></ul></div>"; div.style.background = 'gray'; customFloatingObject.content(div); sheet.floatingObjects.add(customFloatingObject); sheet.pictures.add("f2", "$DEMOROOT$/spread/source/images/splogo.png", 62, 140, 180, 200); sheet.resumePaint(); var floatingObjectEvent = document.getElementById('floatingObjectEvent'); sheet.bind(spreadNS.Events.FloatingObjectSelectionChanged, function (e, args) { var text = floatingObjectEvent.value; if (text !== "") { text += '\n'; } floatingObjectEvent.value = text + "FloatingObjectSelectionChanged: " + args.floatingObject.name(); }); sheet.bind(spreadNS.Events.FloatingObjectChanged, function (e, args) { var text = floatingObjectEvent.value; if (text !== "") { text += '\n'; } floatingObjectEvent.value = text + "FloatingObjectChanged: " + args.floatingObject.name() + " " + args.propertyName; }); sheet.bind(spreadNS.Events.PictureSelectionChanged, function (e, args) { var text = floatingObjectEvent.value; if (text !== "") { text += '\n'; } floatingObjectEvent.value = text + "PictureSelectionChanged: " + args.picture.name(); }); sheet.bind(spreadNS.Events.PictureChanged, function (e, args) { var text = floatingObjectEvent.value; if (text !== "") { text += '\n'; } floatingObjectEvent.value = text + "PictureChanged: " + args.picture.name() + " " + args.propertyName; }); };
<!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"> <textarea id="floatingObjectEvent" style="width: 95%; height: 90px"></textarea> </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; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }