还是不行,ShapeSelectionChanged代码没有触发,获取不到名称
这个添加线条的代码,看看是否有问题
function onLine() {
var spread = GC.Spread.Sheets.Designer.findControl(document.getElementById('ExcelTemplateDiv')).getWorkbook();
var index = spread.getActiveSheetIndex(); //获取控件的活动工作表索引。
var sheet = spread.getSheet(index); // 获取下标为0的工作表
console.log(index)
var command = {
canUndo: true,
execute: function(spread, options, isUndo) {
var Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(spread, options);
return true;
} else {
Commands.startTransaction(spread, options);
var shapeData = [{
type: 'straight',
}]
spread.suspendPaint();
// var sheet = spread.getSheet(0);
// sheet.name("ConnectorShape");
for (var i = 0; i < shapeData.length; i++) {
console.log("shapeData[i]", shapeData[i],shapeData)
initShape(sheet, shapeData[i], i); //add connectorShape
}
sheet.setValue(1, 1, 'STRAIGHT');
sheet.setValue(1, 5, 'ELBOW');
spread.options.tabStripRatio = 0.8;
spread.resumePaint();
Commands.endTransaction(spread, options);
return true;
}
}
};
var rowindex = sheet.getActiveRowIndex(); //获取选择的行信息
var selections = sheet.getSelections();
var commandManager = spread.commandManager();
commandManager.register('initShape', command);
commandManager.execute({
cmd: 'initShape',
sheetName: spread.getSheet(index).name()
});
}
//线条
function initShape(sheet, shapeData, index) {
var colors = ["#000000", "#F8B22E", "black", "#00C2D6"];
var arrowheadStyle = GC.Spread.Sheets.Shapes.ArrowheadStyle;
var arrowheadLength = GC.Spread.Sheets.Shapes.ArrowheadLength;
var arrowheadWidth = GC.Spread.Sheets.Shapes.ArrowheadWidth;
var beginX = 70,
endX = 250;
if (shapeData.type === 'elbow') {
beginX = 320;
endX = 500;
index = index % 4;
}
var connectorShape = sheet.shapes.addConnector('', GC.Spread.Sheets.Shapes.ConnectorType[shapeData.type], beginX,
80 + index * 70, endX, 50 + index * 70);
if (shapeData.beginArrowhead !== undefined) {
var connectorBeginStyle = connectorShape.style();
var beginLine = connectorBeginStyle.line;
beginLine.beginArrowheadStyle = arrowheadStyle[shapeData.beginArrowhead.style];
beginLine.beginArrowheadWidth = arrowheadWidth[shapeData.beginArrowhead.width];
beginLine.beginArrowheadLength = arrowheadLength[shapeData.beginArrowhead.length];
connectorShape.style(connectorBeginStyle);
}
if (shapeData.endArrowhead !== undefined) {
var connectorEndStyle = connectorShape.style();
var endLine = connectorEndStyle.line;
endLine.endArrowheadStyle = arrowheadStyle[shapeData.endArrowhead.style];
endLine.endArrowheadWidth = arrowheadWidth[shapeData.endArrowhead.width];
endLine.endArrowheadLength = arrowheadLength[shapeData.endArrowhead.length];
connectorShape.style(connectorEndStyle);
}
var connectorStyle = connectorShape.style();
var lineTemp = connectorStyle.line;
lineTemp.width = 3;
lineTemp.color = colors[index];
connectorShape.style(connectorStyle);
}
|