本帖最后由 Derrick.Jiao 于 2022-5-9 14:57 编辑
js是14.1,ui是11。在spreadjs工具栏条件功能上下角标,但最近出现问题了,不确定是升级了14.1导致的还是什么?点击上下角标按钮,无法获取到鼠标选中的内容,window.getSelection() 获取不到选中的值。麻烦看下,,角标函数内容:function cornermark(cornermark) { var cornermarkstart = "<" + cornermark + ">";
var cornermarkend = "</" + cornermark + ">";
var userSelection;
if (window.getSelection) {//一般浏览器
userSelection = window.getSelection();
} else if (document.selection) {//IE浏览器、Opera
userSelection = document.selection.createRange();
}
var userSelectionx = userSelection.toString();
// 整个文本
var text = userSelection.anchorNode.data;
// 起点
var anchor = userSelection.anchorOffset;
// 终点
var focus = userSelection.focusOffset;//extentOffset
var length = text.length;
if (anchor > focus) {
anchor += focus;
focus = anchor - focus;
anchor -= focus;
}
if (anchor == focus || length == (focus - anchor)) {
designer.MessageBox.show("请选择部分内容!", "提示", 2); /* 第三个参数控制弹窗显示图标:1提示 2警告 3错误 */
return;
}
var s1 = text.substring(0, anchor);
var s2 = text.substring(anchor, focus);
var s3 = text.substring(focus, length);
var ss = s1 + cornermarkstart + s2 + cornermarkend + s3;
var spread = designer.wrapper.spread;
var activeSheet = spread.getActiveSheet();
var rowindex = activeSheet.getActiveRowIndex();
var columnindex = activeSheet.getActiveColumnIndex();
userSelection.anchorNode.replaceData(anchor, focus - anchor, cornermarkstart + s2 + cornermarkend);
activeSheet.suspendPaint();
activeSheet.setValue(rowindex, columnindex, userSelection.anchorNode.parentElement.innerText);
activeSheet.resumePaint();
activeSheet.suspendPaint();
var cell = activeSheet.getCell(rowindex, columnindex);
cell.cellType(new HTMLCellType());//指定是上下标单元格
activeSheet.resumePaint();
// 判断如果添加上标,则将高度设置为25
var tempHeight = activeSheet.getRowHeight(rowindex, GC.Spread.Sheets.SheetArea.viewport);
var tempValue = cell.text();
if (cornermark === 'sub' || tempValue.indexOf('sub') !== -1) {
if (tempHeight < 28) activeSheet.setRowHeight(rowindex, 28);
} else {
activeSheet.autoFitRow(rowindex);
}
}
|
-
|