I am using AngularJS to read and display the contents of an excel file.
When the excel file contains a row with a value such as:
“Finance Committee will need to meet prior to the board meeting on February 16“
The value gets converted into a date 2/16/01
After this piece of code gets executed (ProcessExcel)
$scope.DisplayFile = function () {
var regex = /^[a-z0-9][-a-z0-9x20_!().:,]*.xlsx?$/i;
if (regex.test($scope.SelectedFile.name)) {
if (typeof (FileReader) !== "undefined") {
var reader = new FileReader();
//For Browsers other than IE.
if (reader.readAsBinaryString) {
reader.onload = function (e) {
$scope.ProcessExcel(e.target.result);
};
reader.readAsBinaryString($scope.SelectedFile);
} else {
//For IE Browser.
reader.onload = function (e) {
var data = "";
var bytes = new Uint8Array(e.target.result);
for (var i = 0; i < bytes.byteLength; i++) {
data += String.fromCharCode(bytes[i]);
}
*$scope.ProcessExcel(data)*; --I think the issue comes from this function, I might be incorrect
$scope.ProcessExcel = function (data) {
//file data
var workbook = XLSX.read(data, {
type: 'binary'
});
//fetch first sheet
var firstSheet = workbook.SheetNames[0];
//put sheet into array excelRows
*excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet]);* -- By the time this assignment occurs, the value of the excel array for that row, is already 2/16/01
Can someone please help me understand how can this be avoided, and corrected?
Thank you,
Erasmo.