[]
SpreadJS allows you to customize the date format based on your system locale settings while importing an Excel file.
For example, when an Excel file containing the date format as dd/mm/yyyy is imported in EN culture, the date format is displayed as dd/mm/yyyy in SpreadJS. But when the same Excel file is imported in French culture, the date format is displayed as yyyy-MM-dd in SpreadJS as it is the default date format in French. The default number format id for French culture is 14. You can set the default number format id to any other number format like: {14: yyyy-M-d} to display the custom date format.
The custom date format can be specified to the default number format id using LocalNumberFormat field, before importing the Excel file in SpreadJS.
The custom date format can be set by using following steps:
Get the Excel built-in number format.
Create new culture info and set the Excel number format to custom format.
Set culture info to Culture Manager.
Import the Excel file.
The example below demonstrates how to set the custom date format to default number format id of French culture.
// Initialize Spread
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
// Get the sheet
var sheet = spread.sheets[0];
var excelIO = new GC.Spread.Excel.IO();
$("#button1").click(function () {
spread.suspendPaint();
// Create new culture info
var culture = new GC.Spread.Common.CultureInfo();
culture.LocalNumberFormat = {
14: "yyyy/m/d"
};
// Set culture info to Culture Manager
GC.Spread.Common.CultureManager.addCultureInfo("fr", culture);
GC.Spread.Common.CultureManager.culture("fr");
// Import Excel file
var excelFile = document.getElementById("fileDemo").files[0];
excelIO.open(excelFile, function (json) {
var workbookObj = json;
spread.fromJSON(workbookObj);
}, function (e) {
console.log(e);
});
spread.resumePaint();