I am currently working with the XLSX npm package and attempting to download a sample Excel file, add some data to it, and then upload it back. The fields in the file include MOBILE NUMBER
, DATE
, TIME
, and NAME
. When I upload the file, the values for the DATE, TIME, and MOBILE NUMBER fields are being received in decimal and exponential formats, so I am attempting to modify the excel column datatype to Text
by default when downloading the Excel file using the code snippet below:
this.headers[0] = ['Name', 'Mobile','Time','Date']
const ws = XLSX.utils.aoa_to_sheet(this.headers);
const wb: XLSX.WorkBook = XLSX.utils.book_new();
var range = XLSX.utils.decode_range(ws['!ref']);
for (var r = range.s.r; r <= range.e.r; r++) {
for (var c = range.s.c; c <= range.e.c; c++) {
var cellName = XLSX.utils.encode_cell({ c: c, r: r });
}
}
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
wb.Sheets['Sheet1']['B1'].z = 'Text';
wb.Sheets['Sheet1']['C1'].z = 'Text';
wb.Sheets['Sheet1']['D1'].z = 'Text';
XLSX.writeFile(wb, 'Sample.xlsx');
Despite using the above code, I am unable to change the column datatype to TEXT
, and I am uncertain if what I am expecting is achievable. Any suggestions would be greatly appreciated. Thank you.