文本省略符

当单元格中的内容超出单元格的范围时,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">显示省略号:</label> <input type="button" value="显示" id="ShowEllipsis" /> <input type="button" value="移除" id="RemoveEllipsis" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">水平对齐:</label> <input type="button" value="左对齐" id="HAlign0" /> <input type="button" value="居中" id="HAlign1" /><br> <input type="button" value="右对齐" id="HAlign2" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">垂直对齐:</label> <input type="button" value="顶部对齐" id="VAlign0" /> <input type="button" value="居中" id="VAlign1" /><br> <input type="button" value="底部对齐" id="VAlign2" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">缩进:</label> <input type="button" value="增加" id="IndentUp" /> <!-- Fixed typo in original ID: "IndentDwon" -> "IndentDown" --> <input type="button" value="减少" id="IndentDown" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">垂直文本:</label> <input type="button" value="垂直" id="Vertical" /> <input type="button" value="正常" id="Normal" /> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">内边距:</label> <table> <tr> <td> <label class="paddingLabel1">顶部:</label><input class="paddingInput1" id="Top" type="number" /><br> </td> <td> <label class="paddingLabel1">右侧:</label><input class="paddingInput1" id="Right" type="number" /><br> </td> </tr> <tr> <td> <label class="paddingLabel1">底部:</label><input class="paddingInput1" id="Bottom" type="number" /><br> </td> <td> <label class="paddingLabel1">左侧:</label><input class="paddingInput1" id="Left" type="number" /> </td> </tr> </table> <input style="margin-left: 117px;" id="SetPadding" type="button" value="设置" /> </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; }