您好,这边调研了一下,请参考以下代码:
- document.querySelector("#button1").addEventListener("click", function () {
- // let spread = designer.getWorkbook();
- // spreadExport(spread);
- spread = designer.getWorkbook();
- sheet = spread.getActiveSheet();
- var customFloatingObject =
- new GC.Spread.Sheets.FloatingObjects.FloatingObject("f1", 10, 10, 60, 64);
- var btn = document.createElement("button");
- btn.style.width = "10px";
- btn.style.height = "10px";
- btn.innerText = "button";
- customFloatingObject.content(btn);
- customFloatingObject.startRow(2);
- customFloatingObject.startColumn(2);
- customFloatingObject.endRow(3);
- customFloatingObject.endColumn(3);
- sheet.floatingObjects.add(customFloatingObject);
- });
- document.querySelector("#button2").addEventListener("click", function () {
- // excelSave(spread, () => {});
- sheet = spread.getActiveSheet();
- let customFloatingObject = sheet.floatingObjects.all()[0];
- customFloatingObject.startRow(2);
- customFloatingObject.startColumn(2);
- customFloatingObject.endRow(3);
- customFloatingObject.endColumn(3);
- customFloatingObject.startRowOffset(0);
- customFloatingObject.startColumnOffset(0);
- customFloatingObject.endRowOffset(0);
- customFloatingObject.endColumnOffset(0);
- });
复制代码
第一个按钮用于创建floatingObject,然后移动该floatingObject到其他的位置后,再点击第二个按钮,此时floatingObject会回到原始的位置,看能否满足您的需求。 |