Hi all,
I'm trying to convert an HTML table to Excel in Javascript using new ActiveXObject("Excel.application")
. Bascially I loop through table cells and insert the value to the corresponding cell in excel:
//for each table cell
oSheet.Cells(x,y).value = cell.innerText;
The problem is that when the cell is in date format of 'dd-mm-yyyy' (e.g. 10-09-2008), excel would read as 'mm-dd-yyyy' (i.e. 09 Oct 2008). I tried to specify NumberFormat
like:
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
But it has no effect. It seems that this only affect how excel display the value, not parse. My only solution now is to swap the date like:
var txt = cell.innerText;
if(/^(\d\d)-(\d\d)-\d\d\d\d$/.test(txt)) txt = txt.replace(/^(\d\d)-(\d\d)/,'$2-$1');
But I'm worrying that it is not generic and a differnt machine setting would fail this.
Is there a way to specific how excel parse the input value?