文本省略符

当单元格中的内容超出单元格的范围时,SpreadJS支持在单元格中显示文本省略号。

你可以通过showEllipsis属性进行省略符的控制, 以演示为例,选择一个单元格并在右侧改变对应的样式属性。 当文本长于列宽时,如果要显示文本省略号,那么文本将不会溢出,你可以使用textOrientation创建样式并设置旋转,如下所示 替换文本为省略符 '…'. 以下功能将会影响文本的省略符显示: Indent(文字缩进) Vertical text(竖向文字) Alignment(文字位置) Padding(内边距) Outline column(分组列)
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 }); initSpread(spread); }; function initSpread(spread) { spread.fromJSON(data); var sheet = spread.getActiveSheet(); document.getElementById('HAlign0').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.hAlign = 0; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('HAlign1').onclick= function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.hAlign = 1; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('HAlign2').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.hAlign = 2; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('VAlign0').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.vAlign = 0; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('VAlign1').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.vAlign = 1; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('VAlign2').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.vAlign = 2; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('IndentUp').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (!isNaN(parseInt(style.textIndent))) { style.textIndent = (parseInt(style.textIndent) + 1) + ""; } else if (style.textIndent === undefined) { style.textIndent = '1'; } sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('IndentDwon').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); if (!isNaN(parseInt(style.textIndent)) && parseInt(style.textIndent) > 0) { style.textIndent = (parseInt(style.textIndent) - 1) + ""; } sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('Vertical').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.isVerticalText = true; style.textOrientation = 0; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('Normal').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.isVerticalText = undefined; style.textOrientation = undefined; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('SetPadding').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.cellPadding = document.getElementById('Top').value + ' ' + document.getElementById('Right').value + ' ' +document.getElementById('Bottom').value + ' '+document.getElementById('Left').value; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('ShowEllipsis').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.showEllipsis = true; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('RemoveEllipsis').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.showEllipsis = undefined; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="spreadjs culture" content="zh-cn" /> <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-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="$DEMOROOT$/spread/source/data/ellipsis.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"> <label id="Text Oriention" for="textOriention">Show Ellipsis:</label> <input type="button" value="Show" id="ShowEllipsis" /> <input type="button" value="Remove" id="RemoveEllipsis" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">HAlign:</label> <input type="button" value="Left" id="HAlign0" /> <input type="button" value="Center" id="HAlign1" /><br> <input type="button" value="Right" id="HAlign2" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">VAlign:</label> <input type="button" value="Top" id="VAlign0" /> <input type="button" value="Center" id="VAlign1" /><br> <input type="button" value="Bottom" id="VAlign2" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">Indent:</label> <input type="button" value="Increase" id="IndentUp" /> <input type="button" value="Decrease" id="IndentDwon" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">Vertical Text:</label> <input type="button" value="Vertical" id="Vertical" /> <input type="button" value="Normal" id="Normal" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">Padding:</label> <table> <tr> <td> <label class="paddingLabel1">Top:</label><input class="paddingInput1" id="Top" type="number" /><br> </td> <td> <label class="paddingLabel1">Right:</label><input class="paddingInput1" id="Right" type="number" /><br> </td> </tr> <tr> <td> <label class="paddingLabel1">Bottom:</label><input class="paddingInput1" id="Bottom" type="number" /><br> </td> <td> <label class="paddingLabel1">Left:</label><input class="paddingInput1" id="Left" type="number" /> </td> </tr> </table> <input style="margin-left: 117px;" id="SetPadding" type="button" 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; } input { width: 100px; } .option-row { font-size: 14px; padding: 5px; } label { display: block; padding-bottom: 5px; } input { padding: 4px 6px; margin-bottom: 6px; margin-right: 10px; } .paddingLabel { width: 113px; display: inline-block; text-align: center; } .paddingLabel1 { width: 50px; /* display: inline-block; */ } .paddingInput { width: 84px; } .paddingInput1 { width: 84px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }