글꼴

SpreadJS는 글꼴, 글꼴 스타일, 굵게, 기울임꼴 같은 다양한 글꼴 스타일을 제공합니다.

다음 코드를 사용하여 글꼴 스타일을 사용자 정의할 수 있습니다. 다음 코드를 사용하여 분할된 글꼴 속성을 기준으로 글꼴을 사용자 정의할 수 있습니다. underline, doubleUnderline, lineThrough, overline 등의 텍스트 장식을 설정할 수도 있습니다. 다음과 같이 글꼴 맞춤을 설정할 수 있습니다. 다음과 같이 글꼴 색 및 셀 배경색을 설정할 수 있습니다. wordwrap, indent, shrinkToFit 같은 글꼴 서식을 설정할 수 있습니다.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> </gc-spread-sheets> <div class="options-container"> <p>Select a cell, Set font for it.</p> <div class="settings-row"> <label for="fontStyle">Font Style:</label> <input type="text" id="fontStyle" v-model="fontStyle"/> </div> <div class="settings-row"> <label for="fontWeight">Font Weight:</label> <input type="text" id="fontWeight" v-model="fontWeight"/> </div> <div class="settings-row"> <label for="fontSize">Font Size:</label> <input id="fontSize" type="number" min="0" v-model="fontSize"/> <select id="fontSizeUnit" v-model="fontSizeUnit"> <option value="px">px</option> <option value="pt">pt</option> </select> </div> <div class="settings-row"> <label for="fontFamily">Font Family:</label> <input id="fontFamily" type="text" v-model="fontFamily"/> </div> <div class="settings-row"> <button id="set-splitted-font" class="settings-btn" v-on:click="setFontBySplittedFont">Set Font Using Font Properties</button> </div> <br/> <div class="settings-row"> <label for="font">Font:</label> <input type="text" id="font" v-model="font"/> </div> <div class="settings-row"> <button id="set-font" class="settings-btn" v-on:click="setFontByFont">Set Font By Font</button> </div> </div> </div> </template> <script> import Vue from 'vue'; import '@mescius/spread-sheets-vue' import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import './styles.css'; function fontStyleOrFontWeightCssValueToSpreadValue (value) { // transfer css font style/weight to spread font style/weight if (value === '') { return undefined; } else if (value === 'normal') { return null; } else { return value; } } function fontStyleOrFontWeightSpreadValueToCssValue (value) { // transfer spread font style/weight to css font style/weight if (value === undefined) { return ''; } else if (value === null) { return 'normal'; } else { return value; } } function setFontToSelectedRanges (spread, setFunc) { let activeSheet = spread.getActiveSheet(); let selections = activeSheet.getSelections(); if (!selections) { return; } activeSheet.suspendPaint(); for (let i = 0; i < selections.length; i++) { let selection = selections[i]; if (!selection) { return; } for (let r = 0; r < selection.rowCount; r++) { for (let c = 0; c < selection.colCount; c++) { let cell = activeSheet.getCell(r + selection.row, c + selection.col); setFunc(cell); } } } activeSheet.resumePaint(); } function setStyles (sheet) { sheet.suspendPaint(); //Font sheet.getCell(2, 0).font('italic normal 12px Mangal'); sheet.getCell(4, 0).font('normal bold 15px Arial Black'); sheet.getCell(6, 0).font('normal normal 18px Georgia'); //FontFamily sheet.getCell(2, 1).fontFamily('Mangal'); sheet.getCell(4, 1).fontFamily('Arial Black'); sheet.getCell(6, 1).fontFamily('Georgia'); //FontSize sheet.getCell(2, 2).fontSize('12px'); sheet.getCell(4, 2).fontSize('20px'); sheet.getCell(6, 2).fontSize('28px'); //Bold sheet.getCell(2, 3).fontWeight('bold'); sheet.getCell(4, 3).fontWeight('normal'); //Italic sheet.getCell(2, 4).fontStyle('italic'); sheet.getCell(4, 4).fontStyle('normal'); //Line sheet.getCell(2, 5).textDecoration(GC.Spread.Sheets.TextDecorationType.underline); sheet.getCell(4, 5).textDecoration(GC.Spread.Sheets.TextDecorationType.doubleUnderline); sheet.getCell(6, 5).textDecoration(GC.Spread.Sheets.TextDecorationType.lineThrough); sheet.getCell(8, 5).textDecoration(GC.Spread.Sheets.TextDecorationType.overline); //Align sheet.getCell(2, 6).vAlign(GC.Spread.Sheets.VerticalAlign.top).hAlign(GC.Spread.Sheets.HorizontalAlign.left); sheet.getCell(4, 6).vAlign(GC.Spread.Sheets.VerticalAlign.center).hAlign(GC.Spread.Sheets.HorizontalAlign.center); sheet.getCell(6, 6).vAlign(GC.Spread.Sheets.VerticalAlign.bottom).hAlign(GC.Spread.Sheets.HorizontalAlign.right); //Forecolor sheet.getCell(2, 7).foreColor('#F7A711'); sheet.getCell(4, 7).foreColor('#82BC00'); sheet.getCell(6, 7).foreColor('#C3C3C3'); //backgroundColor sheet.getCell(2, 8).backColor('#F7A711'); sheet.getCell(4, 8).backColor('#82BC00'); sheet.getCell(6, 8).backColor('#C3C3C3'); //WordWrap sheet.getCell(2, 9).wordWrap(true); sheet.getCell(3, 9).wordWrap(true); //Indent sheet.getCell(2, 10).textIndent(1); sheet.getCell(4, 10).textIndent(3); sheet.getCell(6, 10).textIndent(-2); //ShrinkToFit sheet.getCell(2, 11).shrinkToFit(true).vAlign(GC.Spread.Sheets.VerticalAlign.center); sheet.getCell(4, 11).shrinkToFit(true).vAlign(GC.Spread.Sheets.VerticalAlign.bottom); sheet.resumePaint(); } let App = Vue.extend({ name: "app", data: function() { return { fontStyle: '', fontWeight: '', fontSize: '', fontSizeUnit: 'px', fontFamily: '', font: '', spread: null }; }, methods:{ initSpread(spread) { this.spread = spread; let sheet = spread.getActiveSheet(); sheet.fromJSON(jsonData); setStyles(sheet); this.setSettings(spread); this.bindEvents(spread); }, bindEvents (spread) { let self = this; spread.bind(GC.Spread.Sheets.Events.SelectionChanged, function () { self.setSettings(spread); }); }, setSettings (spread) { let self = this, sheet = spread.getActiveSheet(); let activeCell = sheet.getCell(sheet.getActiveRowIndex(), sheet.getActiveColumnIndex()); self.font = activeCell.font(); self.fontStyle = fontStyleOrFontWeightSpreadValueToCssValue(activeCell.fontStyle()); self.fontWeight = fontStyleOrFontWeightSpreadValueToCssValue(activeCell.fontWeight()); let fontSize = activeCell.fontSize(); if (fontSize) { let fontSizeDigit = parseFloat(fontSize); let fontSizeUnit = fontSize.substring((''+ fontSizeDigit).length); self.fontSize = '' + fontSizeDigit; self.fontSizeUnit = fontSizeUnit; } else { self.fontSize = ''; self.fontSizeUnit = 'px'; } self.fontFamily = activeCell.fontFamily() || ''; }, setFontBySplittedFont () { let self = this, spread = self.spread; let fontStyle = self.fontStyle, fontWeight = self.fontWeight, fontFamily = self.fontFamily, fontSizeDigit = self.fontSize, fontSizeUnit = self.fontSizeUnit, fontSize; if (fontSizeDigit) { fontSize = fontSizeDigit + (fontSizeUnit ? fontSizeUnit : 'px'); } setFontToSelectedRanges(spread, (cell) => { cell.fontStyle(fontStyleOrFontWeightCssValueToSpreadValue(fontStyle)); cell.fontWeight(fontStyleOrFontWeightCssValueToSpreadValue(fontWeight)); cell.fontSize(fontSize); cell.fontFamily(fontFamily); }); self.setSettings(spread); }, setFontByFont () { let self = this, spread = self.spread; let font = self.font; setFontToSelectedRanges(spread, (cell) => { cell.font(font); }); self.setSettings(spread); } }, computed:{ dataSource() { return getData(); } } }); new Vue({ render: h => h(App) }).$mount('#app'); </script>
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/vue/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/ko/vue/node_modules/systemjs/dist/system.src.js"></script> <script src="data.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); System.import('$DEMOROOT$/ko/lib/vue/license.js'); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
var jsonData = { "name": "Sheet1", "isSelected": true, "activeRow": 10, "activeCol": 5, "visible": 1, "theme": "Office", "data": { "dataTable": { "1": { "0": { "value": "Font", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "1": { "value": "FontFamily", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "2": { "value": "FontSize", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "3": { "value": "Bold", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "4": { "value": "Italic", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "5": { "value": "TextDecoration", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "6": { "value": "Align", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "7": { "value": "ForeColor", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "8": { "value": "BackgroundColor", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "9": { "value": "WordWrap", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "10": { "value": "Indent", "style": { "backColor": "#82bc00", "foreColor": "white" } }, "11": { "value": "ShrinkToFit", "style": { "backColor": "#82bc00", "foreColor": "white" } } }, "2": { "0": { "value": "Font" }, "1": { "value": "FontFamily" }, "2": { "value": "FontSize" }, "3": { "value": "Bold" }, "4": { "value": "Italic" }, "5": { "value": "UnderLine" }, "6": { "value": "Align" }, "7": { "value": "Forecolor" }, "8": { "value": "BackColor" }, "9": { "value": "Word-Wrap Word-Wrap Word-Wrap" }, "10": { "value": "Indent" }, "11": { "value": "This is a long text" } }, "3": { "9": { "value": "Word\r\nWrap" } }, "4": { "0": { "value": "Font" }, "1": { "value": "FontFamily" }, "2": { "value": "FontSize" }, "3": { "value": "Bold" }, "4": { "value": "Italic" }, "5": { "value": "DbUnderLine" }, "6": { "value": "Align" }, "7": { "value": "Forecolor" }, "8": { "value": "BackColor" }, "10": { "value": "Indent" }, "11": { "value": "ShrinkToFit" } }, "6": { "0": { "value": "Font" }, "1": { "value": "FontFamily" }, "2": { "value": "FontSize" }, "5": { "value": "lineThrough" }, "6": { "value": "Align" }, "7": { "value": "Forecolor" }, "8": { "value": "BackColor" }, "10": { "value": "Indent" } }, "8": { "5": { "value": "overline" } } }, "defaultDataNode": { "style": { "themeFont": "Body" } } }, "rowHeaderData": { "defaultDataNode": { "style": { "themeFont": "Body" } } }, "colHeaderData": { "defaultDataNode": { "style": { "themeFont": "Body" } } }, "rows": [ null, null, { "size": 50 }, { "size": 50 }, { "size": 50 }, null, { "size": 50 } ], "columns": [ { "size": 120 }, { "size": 120 }, { "size": 120 }, null, null, { "size": 100 }, { "size": 100 }, null, { "size": 120 }, { "size": 80 }, { "size": 80 }, { "size": 100 } ], "defaultData": {}, "leftCellIndex": 0, "topCellIndex": 0, "selections": { "0": { "row": 10, "col": 5, "rowCount": 1, "colCount": 1 }, "length": 1 }, "rowOutlines": { "items": [] }, "columnOutlines": { "items": [] }, "cellStates": {}, "states": {}, "outlineColumnOptions": {}, "autoMergeRangeInfos": [], "shapeCollectionOption": { "snapMode": 0 }, "printInfo": { "paperSize": { "width": 850, "height": 1100, "kind": 1 } } }
.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; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } label { display: inline-block; width: 80px; } .settings-row { width: 100%; height: 30px; font-size: 13px; } .settings-btn { display: inline-block; width: 220px; height: 21px; } #fontSize { width: 80px; } .settings-row input { width: 160px; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.js', 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' } } }); })(this);