テキストの配置

SpreadJSはテキストの配置をサポートしており、水平方向と垂直方向の配置を設定して、思い通りの効果を得ることができます。

次のようにスタイルを作成し、配置を設定できます: その次に、このスタイルをセルに適用して、テキストの配置を設定します。 以下のリストは、SpreadJSで現在サポートされている配置を示します。 水平方向の配置 : Left:左詰め Center:中央揃え Right:右詰め Center Across Selection (CenterContinue):選択範囲内で中央 Distributed:均等割り付け 垂直方向の配置 : Top:上詰め Center:中央揃え Bottom:下詰め
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 }); initSpread(spread); }; function initSpread(spread) { spread.fromJSON(jsonData); var sheet = spread.getActiveSheet(); sheet.suspendPaint(); // set table style sheet.getRange("C5:E5").backColor("Accent 1 80"); sheet.getRange("C6:C13").backColor("Accent 6 80"); sheet.addSpan(5, 2, 5, 1); sheet.addSpan(10, 2, 3, 1); sheet.setColumnWidth(2, 140); sheet.setColumnWidth(3, 200); sheet.setColumnWidth(4, 80); sheet.setRowHeight(10, 60); sheet.setRowHeight(11, 60); sheet.setRowHeight(12, 60); sheet.getRange("C6:C13").vAlign(GC.Spread.Sheets.VerticalAlign.center); sheet.getRange("C6:C13").hAlign(GC.Spread.Sheets.HorizontalAlign.center); sheet.getRange("C5:E5").hAlign(GC.Spread.Sheets.HorizontalAlign.centerContinuous); var lineStyle = GC.Spread.Sheets.LineStyle.dotted; var lineBorder = new GC.Spread.Sheets.LineBorder('black', lineStyle); sheet.getRange("C5:E13").setBorder(lineBorder, { all: true }); // set text sheet.setValue(4, 2, "Text Alignment"); sheet.setValue(5, 2, "Horizontal Alignment"); sheet.setValue(10, 2, "Vertical Alignment"); var hAlignData = [["Left"], ["Center"], ["Right"], ["Center Across Selection"],["Distributed Alignment"]]; var vAlignData = [["Top"], ["Center"], ["Bottom"]]; sheet.setArray(5, 3, hAlignData); sheet.setArray(10, 3, vAlignData); // set Alignment sheet.getStyle(5, 3).hAlign = GC.Spread.Sheets.HorizontalAlign.left; sheet.getStyle(6, 3).hAlign = GC.Spread.Sheets.HorizontalAlign.center; sheet.getStyle(7, 3).hAlign = GC.Spread.Sheets.HorizontalAlign.right; sheet.getRange(8, 3, 1, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.centerContinuous); sheet.getStyle(9, 3).hAlign = GC.Spread.Sheets.HorizontalAlign.distributed; sheet.getStyle(10, 3).vAlign = GC.Spread.Sheets.VerticalAlign.top; sheet.getStyle(11, 3).vAlign = GC.Spread.Sheets.VerticalAlign.center; sheet.getStyle(12, 3).vAlign = GC.Spread.Sheets.VerticalAlign.bottom; sheet.resumePaint(); 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('HAlign3').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.hAlign = 4; sheet.setStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex(), style); }; document.getElementById('HAlign4').onclick = function () { var style = sheet.getActualStyle(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); style.hAlign = 5; 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); }; }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/alignment.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/jquery-1.8.2.min.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="Left" id="HAlign0" /> <input type="button" value="Center" id="HAlign1" /><br> <input type="button" value="Right" id="HAlign2" /> <input type="button" value="CenterContinues" id="HAlign3"> <input type="button" value="Distributed" id="HAlign4"> </div> <div class="option-row"> <label id="Text Oriention" for="textOriention">垂直方向の配置:</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> </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: 115px; } .option-row { font-size: 14px; padding: 5px; } label { display: block; padding-bottom: 5px; } input { padding: 4px 6px; margin-bottom: 6px; margin-right: 5px; } .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; }