任意のフォントスタイルにカスタマイズするには、次のようなコードを使用します。なお、フォントの指定方法は、CSSフォント定義に従います。
引き続き、下線、二重線、取り消し線、上線などの特殊な文字装飾を設定できます。
フォントの配置を設定するには、次のようなコードを使用します。
フォントの色やセルの背景色を設定するには、次のようなコードを使用します。
テキストの折り返し表示、インデント、縮小による全体表示など、フォント書式も設定できます。
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('#82bc00').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('#F7A711');
sheet.getCell(4, 7).text('Forecolor').foreColor('#82BC00');
sheet.getCell(6, 7).text('Forecolor').foreColor('#C3C3C3');
//backgroundColor
sheet.getCell(2, 8).text('BackColor').backColor('#F7A711');
sheet.getCell(4, 8).text('BackColor').backColor('#82BC00');
sheet.getCell(6, 8).text('BackColor').backColor('#C3C3C3');
//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;
}