Convert HTML to Excel #748

Closed
opened 2017-07-25 10:21:40 +00:00 by sangpuion · 2 comments
sangpuion commented 2017-07-25 10:21:40 +00:00 (Migrated from github.com)

When convert HTML table to Excel, is there any way to force all output as string?

	var wopts = { bookType: type, bookSST: false, type: 'binary' },
		wb = {
			SheetNames: [],
			Sheets: {}
		},
		fname = (String(fn).replace(/\W/g, "") || 'Report.').substring(0,25) + "." + type,
		ws = XLSX.utils.table_to_sheet(document.getElementById(newId));

		wb.SheetNames.push(fname);
		wb.Sheets[fname] = ws;
		wbout = XLSX.write(wb, wopts);

By default, the leading zero for code was trimmed upon export.
Also, number field with "," was considered as string where same data piece less than 1000 was considered as number. The output is annoying.

Any suggestion?
Thanks.

When convert HTML table to Excel, is there any way to force all output as string? var wopts = { bookType: type, bookSST: false, type: 'binary' }, wb = { SheetNames: [], Sheets: {} }, fname = (String(fn).replace(/\W/g, "") || 'Report.').substring(0,25) + "." + type, ws = XLSX.utils.table_to_sheet(document.getElementById(newId)); wb.SheetNames.push(fname); wb.Sheets[fname] = ws; wbout = XLSX.write(wb, wopts); By default, the leading zero for code was trimmed upon export. Also, number field with "," was considered as string where same data piece less than 1000 was considered as number. The output is annoying. Any suggestion? Thanks.
SheetJSDev commented 2017-07-25 22:28:52 +00:00 (Migrated from github.com)

@sangpuion the option raw:true should be passing the raw strings, but it currently isn't. The equivalent for CSV was added in https://github.com/SheetJS/js-xlsx/pull/722 and a similar change would have to be made in https://github.com/SheetJS/js-xlsx/blob/master/bits/79_html.js#L133

@sangpuion the option `raw:true` should be passing the raw strings, but it currently isn't. The equivalent for CSV was added in https://github.com/SheetJS/js-xlsx/pull/722 and a similar change would have to be made in https://github.com/SheetJS/js-xlsx/blob/master/bits/79_html.js#L133
medeirosjoaquim commented 2019-08-13 20:15:21 +00:00 (Migrated from github.com)

When convert HTML table to Excel, is there any way to force all output as string?

	var wopts = { bookType: type, bookSST: false, type: 'binary' },
		wb = {
			SheetNames: [],
			Sheets: {}
		},
		fname = (String(fn).replace(/\W/g, "") || 'Report.').substring(0,25) + "." + type,
		ws = XLSX.utils.table_to_sheet(document.getElementById(newId));

		wb.SheetNames.push(fname);
		wb.Sheets[fname] = ws;
		wbout = XLSX.write(wb, wopts);

By default, the leading zero for code was trimmed upon export.
Also, number field with "," was considered as string where same data piece less than 1000 was considered as number. The output is annoying.

Any suggestion?
Thanks.

Use Sheet instead of WorkSheet. Like:

 const worksheet: XLSX.Sheet = XLSX.utils.table_to_sheet(this.table.nativeElement, {raw: true});
> When convert HTML table to Excel, is there any way to force all output as string? > > ``` > var wopts = { bookType: type, bookSST: false, type: 'binary' }, > wb = { > SheetNames: [], > Sheets: {} > }, > fname = (String(fn).replace(/\W/g, "") || 'Report.').substring(0,25) + "." + type, > ws = XLSX.utils.table_to_sheet(document.getElementById(newId)); > > wb.SheetNames.push(fname); > wb.Sheets[fname] = ws; > wbout = XLSX.write(wb, wopts); > ``` > > By default, the leading zero for code was trimmed upon export. > Also, number field with "," was considered as string where same data piece less than 1000 was considered as number. The output is annoying. > > Any suggestion? > Thanks. Use Sheet instead of WorkSheet. Like: ``` const worksheet: XLSX.Sheet = XLSX.utils.table_to_sheet(this.table.nativeElement, {raw: true}); ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#748
No description provided.