边框样式

使用SpreadJS,可以为形状添加边框并为这些边框应用不同的格式,例如:颜色、透明度、宽度等。

您可以使用 Shape API 自定义基本形状的属性: text: 获取或设置形状的文本。 style: 获取或设置形状的样式。 您可以使用 ConnectorShape API 自定义线条的属性: style: 获取或设置线条形状的样式。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); initEvent(spread); }; var lineCapStyle = { flat: 2, square: 1, round: 0 }; var lineJoinStyle = { round: 0, miter: 1, bevel: 2 }; var lineDashStyle = { solid: 0, squareDot: 1, dash: 2, longDash: 3, dashDot: 4, longDashDot: 5, longDashDotDot: 6, sysDash: 7, sysDot: 8, sysDashDot: 9, dashDotDot: 10 }; var activeShape; function fillShapeTypeList(type, dom) { var names = []; for (var name in type) { if(name === "none" || (parseInt(name, 10)) == name) { continue; } names.push({name: name, value: type[name]}); } names.sort(function (a, b) { return a.name > b.name ? 1 : -1 }); var html = ""; names.forEach(function (item) { html += '<option value="' + item.value + '">' + item.name + '</option>'; }); dom.innerHTML= html; } function getActiveConnectorShape(sheet) { return sheet.shapes.all().filter(function(sp){ return sp.isSelected() && sp instanceof GC.Spread.Sheets.Shapes.ConnectorShape; }); } function initSpread(spread) { setBorderPropVisibility("none"); fillShapeTypeList(lineDashStyle, _getElementById("borderLineStyle")); fillShapeTypeList(lineCapStyle, _getElementById("borderCapLineStyle")); fillShapeTypeList(lineJoinStyle, _getElementById("borderJoinLineStyle")); let oval = spread.getActiveSheet().shapes.add("oval", GC.Spread.Sheets.Shapes.AutoShapeType.oval, 40, 20, 150, 150); let ovalStyle = oval.style(); ovalStyle.fill.color = "#FFFFFF"; oval.style(ovalStyle); var rectangle = spread.getActiveSheet().shapes.add("rectangle", GC.Spread.Sheets.Shapes.AutoShapeType.rectangle, 40, 230, 150, 150); let rectangleStyle = rectangle.style(); rectangleStyle.fill.color = "#FFFFFF"; rectangle.style(rectangleStyle); spread.getActiveSheet().shapes.addConnector("line", GC.Spread.Sheets.Shapes.ConnectorType.straight, 250, 20, 400, 150); spread.getActiveSheet().shapes.addConnector("line", GC.Spread.Sheets.Shapes.ConnectorType.elbow, 250, 250, 400, 350); } function setBorderPropVisibility(display) { var borderProp = _getElementById("borderProp"); borderProp.style.display = display; } function initEvent(spread) { var spreadNS = GC.Spread.Sheets; var sheet = spread.getActiveSheet(); sheet.bind(spreadNS.Events.ShapeSelectionChanged, function () { var selectedShape = sheet.shapes.all().filter(function(sp){ return sp.isSelected(); }); var isShapeSelected = false, isConnectorSelected = false; if (selectedShape.length > 0) { selectedShape.forEach(function (shape) { if (!isShapeSelected && shape instanceof spreadNS.Shapes.Shape) { isShapeSelected = true; } else if (!isConnectorSelected && shape instanceof spreadNS.Shapes.ConnectorShape) { isConnectorSelected = true; } }); setBorderPropVisibility("block"); } else { setBorderPropVisibility("none"); } }); _getElementById("borderColorActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'color', _getElementById("borderColorStyle")); }); _getElementById("borderTransparencyActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'transparency', _getElementById("borderTransparencyStyle")); }); _getElementById("borderWidthActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'width', _getElementById("borderWidthStyle")); }); _getElementById("borderLineStyleActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'lineStyle', _getElementById("borderLineStyle")); }); _getElementById("borderCapLineActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'capType', _getElementById("borderCapLineStyle")); }); _getElementById("borderJoinLineActionBtn").addEventListener('click', function() { _handleShapeBorderAction(spread, 'joinType', _getElementById("borderJoinLineStyle")); }); } function _handleShapeBorderAction(spread, action, valueDom) { var sheet = spread.getActiveSheet(); activeShape = sheet.shapes.all().filter(function (sp) { return sp.isSelected(); }); if (activeShape) { activeShape.forEach(function (shape) { var shapeStyle = shape.style(); shapeStyle.line[action] = valueDom.value; shape.style(shapeStyle); }); sheet.repaint(); } } function _getElementById(id){ return document.getElementById(id); }
<!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-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-shapes/dist/gc.spread.sheets.shapes.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 class="option-row"> Try selecting a shape and change the border properties to see the effect: </div> <div id="divideLine" class="divide-line"></div> <div id="borderProp" class="option-row"> <label>Border Color: </label> <input id="borderColorStyle" data-attr="color" type="color" value="#00A2E8" /> <input type="button" id='borderColorActionBtn' value="Set" /> <label>Border Transparency: </label> <input id="borderTransparencyStyle" data-attr="transparency" type="text" value="0.5" /> <input type="button" id='borderTransparencyActionBtn' value="Set" /> <label>Border Width: </label> <input id="borderWidthStyle" data-attr="width" type="number" value="1" /> <input type="button" id='borderWidthActionBtn' value="Set" /> <label>Border Line Style: </label> <select id="borderLineStyle" data-attr="lineStyle"></select> <input type="button" id='borderLineStyleActionBtn' value="Set" /> <label>Border Cap Line Style: </label> <select id="borderCapLineStyle" data-attr="capType"></select> <input type="button" id='borderCapLineActionBtn' value="Set" /> <label>Border Join Line Style: </label> <select id="borderJoinLineStyle" data-attr="joinType"></select> <input type="button" id='borderJoinLineActionBtn' value="Set" /> </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; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding-left: 5px; } .divide-line { width: 100%; height: 1px; background: #cbcbcb; margin-top: 10px; margin-bottom: 3px; } .title { text-align: center; font-weight: bold; } label { display: block; margin-top: 15px; margin-bottom: 5px; } p { padding: 2px 10px; background-color: #F4F8EB; } input { width: 160px; margin-left: 10px; display: inline; } input[type=button] { width: 50px; margin-left: 1px; } select { width: 160px; margin-left: 10px; display: inline; } textarea { width: 160px; margin-left: 10px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }