[]
SpreadJS supports the UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere.
Typically, the UMD pattern in SpreadJS includes support for AMD (Asynchronous Module Dependency) and CommonJS, which are module specifications that enable developers to write code in a modular way. The modular programming done using UMD patterns not only helps in achieving code reusability but also enhances code efficiency while saving considerable amount of time and resources. Besides this, it can help you in providing solutions to some of the common programming problems without any dependency of writing scripts in a certain order while coding in JavaScript.
SpreadJS now fully supports UMD patterns, including the use of modules usage, as well as corresponding plugins and resources.
The AMD (browser-first) dependencies can be asynchronously loaded to avoid a situation where the browser is likely to loose response.
The following code sample shows how to configure RequireJS, initialize SpreadJS using AMD.
// Configuring RequireJS
<script type="text/javascript">
requirejs.config({
"baseUrl": "./lib",
"paths": {
"spread-sheets": "gc.spread.sheets.all.x.x.x",
"spread-sheets-io": "gc.spread.sheets.io.x.x.x"
}
});
</script>
// Initializing SpreadJS
<script type="text/javascript">
require(['spread-sheets', 'spread-sheets-io'], function (GC) {
var spread = new GC.spread.sheets.Workbook("ss");
saveToExcel(spread);
});
function saveToExcel(spread) {
spread.export(function (blob) {
//save blob to excel.
}, function (e) {
if (e.errorCode === 1) {
alert(e.errorMessage);
}
});
}
</script>
The Common JS (server-first) dependencies makes the javascript code run in the integrated development environment(IDE).
The following code sample shows how to initialize SpreadJS using Common JS.
var GC = require('@mescius/spread-sheets');
require('@mescius/spread-sheets-io');
var spread = new GC.Spread.Sheets.Workbook();
spread.export(function(blob){
//save blod to excel file.
},function(e){
if (e.errorCode){
console.error(e.errorMessage);
}
});