Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Update serial-output.component.ts
Browse files Browse the repository at this point in the history
fixed problems regarding file name and IE support
  • Loading branch information
JeftadeGraaf committed Dec 28, 2023
1 parent 24696a1 commit c9275bd
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,23 @@ export class SerialOutputComponent implements AfterViewInit, OnInit {

exportToCsv() {
var data = this.serialDataAsJSON
var filename = 'TEST_NAME.csv'
var filename = 'serial_monitor_export.csv'

const csv = Papa.unparse(data, {
header: true
});

const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
if (navigator.msSaveBlob) {
// For IE 10+
navigator.msSaveBlob(blob, filename);
} else {
const link = document.createElement('a');
if (link.download !== undefined) {
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

const link = document.createElement('a');
if (link.download !== undefined) {
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

}}

ngAfterViewInit() {
Expand Down

0 comments on commit c9275bd

Please sign in to comment.