문자열 포맷

문자열 포맷은 SpreadJS의 스타일 포맷터에 대한 업데이트다. 워크북의 셀은 텍스트 값 템플릿의 일부로, 수식과 텍스트를 둘 다 가질 수 있다. 이것들은 스파크라인 수식과 같은 다른 스프레드시트 기능과 결합되어 워크시트 셀 내부에 사용자 정의 형식을 만들 수 있다. 개발자는 자바스크립트 코드를 작성하여 문자열 포맷을 스타일의 포맷터로 설정할 수 있다.

설명
app.vue
index.html

포맷터는 다음과 같은 세 가지 경우로 나뉩니다.

  • 일반 셀 포맷터: 표준 포맷터 구문 형식.
  • 수식 형식 문자열: 표준 수식 구문 형식.
  • 텍스트 템플릿 형식 문자열: "{{" 와 "}}"으로 수식이 들어 있는 텍스트 문자열.

과거에는 하나의 셀에서 값과 수식을 동시에 설정할 수 없었지만, 이제는 수식을 스타일 포맷터로 설정할 수 있습니다.

    var style = new GC.Spread.Sheets.Style();
    style.formatter = "=BC_CODE49(CONCAT(A1,A2))"
    sheet.setStyle(0, 0, style);
    sheet.getCell(1, 1, 3).formatter('=BC_CODE128(B2,,,"TRUE","top","B","Arial","normal")');

이 템플릿은 텍스트 값과 수식의 문자열이며, 수식을 문자열로 감싸기 위해 "{{"와 "}}"를 사용하고, 수식에서 여전히 현재 셀을 참조할 수 있습니다.

    sheet.addCustomName('Sales',"=A1:A5", 1, 1);
    var style = new GC.Spread.Sheets.Style();
    style.formatter = "On {{=TEXT(TODAY(),A4)}} Total Sales Were: {{=SUM(Sales)}}";
    sheet.setStyle(5, 0, style);

우리는 '@' 기호를 제공하며, 이 기호는 현재 셀 참조를 나타냅니다. 수식 또는 텍스트 값 템플릿에서 직접 사용할 수 있습니다.

    sheet.addCustomName('Sales',"=A1:A5", 1, 1);
    var style = new GC.Spread.Sheets.Style();
    style.formatter = "On {{=TEXT(TODAY(),@)}} Total Sales Were: {{=SUM(Sales)}}";
    sheet.setStyle(5, 0, style);
    sheet.getCell(0, 0, 3).formatter('=BC_CODE128(@,,,"TRUE","top","B","Arial","normal")');

통합 문서 json 직렬화에 대한 saveAsView 옵션을 제공합니다. 이 옵션은 서식 문자열 결과를 Excel에 저장하는 데 도움이 됩니다.

    spread.toJSON({ saveAsView: true });
포맷터는 다음과 같은 세 가지 경우로 나뉩니다. 일반 셀 포맷터: 표준 포맷터 구문 형식. 수식 형식 문자열: 표준 수식 구문 형식. 텍스트 템플릿 형식 문자열: "{{" 와 "}}"으로 수식이 들어 있는 텍스트 문자열. 과거에는 하나의 셀에서 값과 수식을 동시에 설정할 수 없었지만, 이제는 수식을 스타일 포맷터로 설정할 수 있습니다. 이 템플릿은 텍스트 값과 수식의 문자열이며, 수식을 문자열로 감싸기 위해 "{{"와 "}}"를 사용하고, 수식에서 여전히 현재 셀을 참조할 수 있습니다. 우리는 '@' 기호를 제공하며, 이 기호는 현재 셀 참조를 나타냅니다. 수식 또는 텍스트 값 템플릿에서 직접 사용할 수 있습니다. 통합 문서 json 직렬화에 대한 saveAsView 옵션을 제공합니다. 이 옵션은 서식 문자열 결과를 Excel에 저장하는 데 도움이 됩니다.
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet :autoGenerateColumns='autoGenerateColumns'> </gc-worksheet> </gc-spread-sheets> <div class="options-container"> <div class="option-row" style="padding:2px 10px"> <p> By changing the value of D2 to select the currency calculation strategy, you will notice that the table on the left has changed. </p> </div> </div> </div> </template> <script setup> import '@mescius/spread-sheets-vue' import { ref } from "vue"; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); const spreadRef = ref(null); const autoGenerateColumns = ref(false); function initSpread(spread) { spreadRef.value = spread; spread.suspendPaint(); let sheet = spread.getSheet(0); let gcns = GC.Spread.Sheets; let data = [ [, "FY 2019"], [, "Sales"], [, "Monthly", "Cumulative"], ["Apr", 188897, 188897], ["May", 208146, 397043], ["Jun", 226196, 623239], ["Jul", 277318, 900557], ["Aug", 263273, 1163830], ["Sep", 259845, 1423675], ["Oct", 241047, 1664722], ["Nov", 256306, 1921028], ["Dec", 195845, 2116873], ["Jan", 204934, 2321808], ["Feb", 257852, 2579660], ["Mar", 227779, 2807439] ]; sheet.setArray(3, 1, data); sheet.setColumnWidth(2, 110); sheet.setColumnWidth(3, 110); sheet.setRowCount(20); sheet.setColumnCount(9); sheet.options.gridline.showHorizontalGridline = false; sheet.options.gridline.showVerticalGridline = false; sheet.getRange(3, 1, 15, 3).setBorder( new gcns.LineBorder("black", gcns.LineStyle.medium), { all: true }); sheet.addSpan(3, 2, 1, 2); sheet.addSpan(4, 2, 1, 2); sheet.getRange(3, 2, 3, 2).backColor('#CFE1F3').hAlign(gcns.HorizontalAlign.center); sheet.getRange(6, 1, 12, 1).backColor('#CCC1DA'); let cMapSource = [ { "Currency": "USD", "Value": 1, "Symbol": "$" }, { "Currency": "CNY", "Value": 7.02, "Symbol": "¥" }, { "Currency": "JPY", "Value": 108.8, "Symbol": "¥" }, { "Currency": "EURO", "Value": 0.91, "Symbol": "€" }, ]; sheet.tables.addFromDataSource('cT', 3, 5, cMapSource); [5, 6, 7].forEach((col) => { sheet.setColumnWidth(col, 80); }); sheet.getCell(1, 2).value("Unit:").hAlign(gcns.HorizontalAlign.right); sheet.getRange(1, 3, 1, 1).backColor("yellow").setBorder( new gcns.LineBorder("blue", gcns.LineStyle.medium), { all: true }); let dv1 = gcns.DataValidation.createFormulaListValidator('=cT[[#Data], [Currency]]'); sheet.setDataValidator(1, 3, dv1); sheet.getCell(1, 3).hAlign(gcns.HorizontalAlign.center).value("USD"); sheet.getRange(6, 2, 12, 2) .hAlign(gcns.HorizontalAlign.center) .formatter('=VLOOKUP($D$2,cT[#Data],3,FALSE)&" "&TEXT(@*VLOOKUP($D$2,cT[#Data],2,FALSE),"###,###")'); spread.resumePaint(); } </script> <style scoped> .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; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } </style>
<!DOCTYPE html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>SpreadJS VUE</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ko/vue3/node_modules/systemjs/dist/system.src.js"></script> <script src="./systemjs.config.js"></script> <script src="./compiler.js" type="module"></script> <script> var System = SystemJS; System.import("./src/app.js"); System.import('$DEMOROOT$/ko/lib/vue3/license.js'); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
(function (global) { SystemJS.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, packageConfigPaths: [ './node_modules/*/package.json', "./node_modules/@mescius/*/package.json", "./node_modules/@babel/*/package.json", "./node_modules/@vue/*/package.json" ], map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-io': 'npm:@mescius/spread-sheets-io/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', 'vue': "npm:vue/dist/vue.esm-browser.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", }, meta: { '*.css': { loader: 'systemjs-plugin-css' }, '*.vue': { loader: "../plugin-vue/index.js" } } }); })(this);