Language Package

SpreadJS supports calculation engine packages that provide a way to use formulas in different languages.

<p>To use language, you need to import the resource js file as follows:</p> <pre><code class="hljs html language-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">".../gc.spread.calcengine.languagepackage.x.x.x.min.js"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span> </code></pre> <p>You can use following code to switch language package</p> <pre><code class="hljs js language-js">GC.Spread.CalcEngine.LanguagePackages.languagePackages(<span class="hljs-string">'fr'</span>); </code></pre> <p>When you want to change another language, please recalculate the spread formula by calling the following code:</p> <pre><code class="hljs js language-js">sheet.recalcAll(<span class="hljs-literal">true</span>); </code></pre> <h3 id="language-package-effection">Language Package Effection</h3> <ul> <li>Function name resource like 'SUM' will changes to 'SOMME' in French.</li> <li>Table function name resource like '#ALL, #Data' will changes to '#Tout, #Données' in French.</li> <li>Special function logic like 'LENB' will be different result in different language.</li> <li>CalcError name resource like '#NULL!' will be '#NOM?' in French.</li> <li>Boolean value resource like 'FALSE' will be 'FAUX' in French.</li> </ul>
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss')); initSpread(spread); }; function initSpread(spread) { var sheet = spread.getActiveSheet(); spread.suspendPaint(); sheet.setColumnWidth(0, 20); sheet.setColumnWidth(1, 130); sheet.setColumnWidth(2, 70); sheet.setColumnWidth(3, 70); sheet.setColumnWidth(4, 70); sheet.setColumnWidth(5, 100); var source = [ { Course: "Calculus", Term: 1, Credit: 5, Score: 80, Teacher: "Nancy.Feehafer" }, { Course: "P.E.", Term: 1, Credit: 3.5, Score: 85, Teacher: "Andrew.Cencini" }, { Course: "Political Economics", Term: 1, Credit: 3.5, Score: 95, Teacher: "Jan.Kotas" }, { Course: "Basic of Computer", Term: 1, Credit: 2, Score: 85, Teacher: "Steven.Thorpe" }, { Course: "Micro-Economics", Term: 1, Credit: 4, Score: 62, Teacher: "Jan.Kotas" }, { Course: "Linear Algebra", Term: 2, Credit: 5, Score: 73, Teacher: "Nancy.Feehafer" }, { Course: "Accounting", Term: 2, Credit: 3.5, Score: 86, Teacher: "Nancy.Feehafer" }, { Course: "Statistics", Term: 2, Credit: 5, Score: 85, Teacher: "Robert.Zare" }, { Course: "Marketing", Term: 2, Credit: 4, Score: 70, Teacher: "Laura.Giussani" } ]; var table = sheet.tables.addFromDataSource("Table1", 2, 1, source, GC.Spread.Sheets.Tables.TableThemes.medium2); sheet.setValue(0, 1, "Switch the language and check the SUM formula changes"); sheet.setValue(12, 2, "SUM:"); sheet.setFormula(12, 3, "=SUM(Table1[[#Data], [Credit]])"); sheet.setFormula(12, 4, "=FORMULATEXT(D13)"); sheet.setValue(15, 2, "LENB:"); sheet.setFormula(15, 3, '=LENB("中文")'); sheet.setFormula(15, 4, "=FORMULATEXT(D16)"); spread.resumePaint(); var selectDiv = document.getElementById('languageSelect'); selectDiv.addEventListener('change',function() { var languageName = this.value; GC.Spread.CalcEngine.LanguagePackages.languagePackages(languageName); sheet.recalcAll(true); }); };
<!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$/en/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets-languagepackages/dist/gc.spread.calcengine.languagepackages.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 class="options-container"> <div class="option-row"> Try changing the formula language with the drop-down menu and then double click cell D13 to see the localized function name. <select id="languageSelect"> <option value="en">English</option> <option value="zh">China</option> <option value="ja">Japan</option> <option value="ko">korea/Korean </option> <option value="fr">French</option> <option value="nl">Dutch</option> <option value="de">German</option> <option value="es">Spanish</option> <option value="pt">Portuguese</option> <option value="ru">Russian</option> <option value="sv">Swedish</option> <option value="it">Italian</option> <option value="da">Danish</option> <option value="pl">Polish</option> <option value="fi">Finnish</option> <option value="no">Norwegian</option> <option value="cs">Czech </option> <option value="hu">Hungarian</option> <option value="tr">Turkish</option> </select> </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; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row { margin-bottom: 12px; } input[type=button] { padding: 4px 6px; margin-bottom: 6px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }