フォント

SpreadJSでは、フォント、フォントスタイル、太字、斜体などのリッチフォントスタイルがサポートされます。

<p>任意のフォントスタイルにカスタマイズするには、次のようなコードを使用します。なお、フォントの指定方法は、CSSフォント定義に従います。</p> <pre><code class="hljs js language-js"> sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'FontStyle'</span>).font(<span class="hljs-string">'italic bold 15px/30px Georgia'</span>); </code></pre> <p>引き続き、下線、二重線、取り消し線、上線などの特殊な文字装飾を設定できます。</p> <pre><code class="hljs js language-js"> <span class="hljs-keyword">var</span> style = <span class="hljs-keyword">new</span> GC.Spread.Sheets.Style(); style.textDecoration = GC.Spread.Sheets.TextDecorationType.doubleUnderline; sheet.setStyle(<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,style); </code></pre> <p>フォントの配置を設定するには、次のようなコードを使用します。</p> <pre><code class="hljs js language-js"> sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'Align'</span>).vAlign(GC.Spread.Sheets.VerticalAlign.top).hAlign(GC.Spread.Sheets.HorizontalAlign.left); </code></pre> <p>フォントの色やセルの背景色を設定するには、次のようなコードを使用します。</p> <pre><code class="hljs js language-js"> sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'Forecolor'</span>).foreColor(<span class="hljs-string">'red'</span>); sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'BackColor'</span>).backColor(<span class="hljs-string">'red'</span>); </code></pre> <p>テキストの折り返し表示、インデント、縮小による全体表示など、フォント書式も設定できます。</p> <pre><code class="hljs js language-js"> sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'WordWrap'</span>).wordWrap(<span class="hljs-literal">true</span>); sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'Indent'</span>).textIndent(<span class="hljs-number">1</span>); sheet.getCell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).text(<span class="hljs-string">'ShrinkToFit'</span>).shrinkToFit(<span class="hljs-literal">true</span>); </code></pre>
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss')); var sheet = spread.getActiveSheet(); sheet.suspendPaint(); sheet.setText(1, 1, 'Font'); sheet.setText(1, 2, 'FontSize'); sheet.setText(1, 3, 'Bold'); sheet.setText(1, 4, 'Italic'); sheet.setText(1, 5, 'TextDecoration'); sheet.setText(1, 6, 'Align'); sheet.setText(1, 7, 'ForeColor'); sheet.setText(1, 8, 'BackgroundColor'); sheet.setText(1, 9, 'WordWrap'); sheet.setText(1, 10, 'Indent'); sheet.setText(1, 11, 'ShrinkToFit'); var c, r; for (c = 1; c < 12; c++) { sheet.getCell(1, c).backColor('blue').foreColor('white'); } sheet.setColumnWidth(2, 120); sheet.setColumnWidth(5, 100); sheet.setColumnWidth(6, 100); sheet.setColumnWidth(8, 120); sheet.setColumnWidth(9, 80); sheet.setColumnWidth(10, 80); sheet.setColumnWidth(11, 100); sheet.setRowHeight(2, 50); sheet.setRowHeight(3, 50); sheet.setRowHeight(4, 50); sheet.setRowHeight(6, 50); //Font sheet.getCell(2, 1).text('Font').font('normal normal 15px Mangal'); sheet.getCell(4, 1).text('Font').font('normal normal 15px Arial Black'); sheet.getCell(6, 1).text('Font').font('normal normal 15px Georgia'); //FontSize sheet.getCell(2, 2).text('FontSize').font('normal normal 15px normal'); sheet.getCell(4, 2).text('FontSize').font('normal normal 20px normal'); sheet.getCell(6, 2).text('FontSize').font('normal normal 25px normal'); //Bold sheet.getCell(2, 3).text('Bold').font('bold normal 15px normal'); sheet.getCell(4, 3).text('Bold').font('normal normal 15px normal'); //Italic sheet.getCell(2, 4).text('Italic').font('italic normal 15px normal'); sheet.getCell(4, 4).text('Italic').font('normal normal 15px normal'); //Line sheet.getCell(2, 5).text('UnderLine').textDecoration(GC.Spread.Sheets.TextDecorationType.underline); sheet.getCell(4, 5).text('DbUnderLine').textDecoration(GC.Spread.Sheets.TextDecorationType.doubleUnderline); sheet.getCell(6, 5).text('lineThrough').textDecoration(GC.Spread.Sheets.TextDecorationType.lineThrough); sheet.getCell(8, 5).text('overline').textDecoration(GC.Spread.Sheets.TextDecorationType.overline); //Align sheet .getCell(2, 6) .text('Align') .vAlign(GC.Spread.Sheets.VerticalAlign.top) .hAlign(GC.Spread.Sheets.HorizontalAlign.left); sheet .getCell(4, 6) .text('Align') .vAlign(GC.Spread.Sheets.VerticalAlign.center) .hAlign(GC.Spread.Sheets.HorizontalAlign.center); sheet .getCell(6, 6) .text('Align') .vAlign(GC.Spread.Sheets.VerticalAlign.bottom) .hAlign(GC.Spread.Sheets.HorizontalAlign.right); //Forecolor sheet.getCell(2, 7).text('Forecolor').foreColor('red'); sheet.getCell(4, 7).text('Forecolor').foreColor('blue'); sheet.getCell(6, 7).text('Forecolor').foreColor('green'); //backgroundColor sheet.getCell(2, 8).text('BackColor').backColor('red'); sheet.getCell(4, 8).text('BackColor').backColor('yellow'); sheet.getCell(6, 8).text('BackColor').backColor('green'); //WordWrap sheet.getCell(2, 9).text('Word-Wrap Word-Wrap Word-Wrap').wordWrap(true); sheet.getCell(3, 9).text('Word\nWrap').wordWrap(true); //Indent sheet.getCell(2, 10).text('Indent').textIndent(1); sheet.getCell(4, 10).text('Indent').textIndent(3); sheet.getCell(6, 10).text('Indent').textIndent(-2); //ShrinkToFit sheet.getCell(2, 11).text('This is a long text').shrinkToFit(true).vAlign(GC.Spread.Sheets.VerticalAlign.center); sheet.getCell(4, 11).text('ShrinkToFit').shrinkToFit(true).vAlign(GC.Spread.Sheets.VerticalAlign.bottom); sheet.resumePaint(); };
<!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/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/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="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> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }