Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"markdown-it": "14.3.0",
"rxjs": "7.8.2",
"tslib": "2.8.1",
"xlsx": "0.18.5",
"yaml": "2.9.0",
"yamljs": "0.3.0",
"zone.js": "0.15.1"
Expand Down
43 changes: 37 additions & 6 deletions src/app/pages/mapping/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { MatSort, MatSortModule } from '@angular/material/sort';
import { COMMA, ENTER } from '@angular/cdk/keycodes';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as XLSX from 'xlsx';

import { LoaderService } from 'src/app/service/loader/data-loader.service';
import {
DialogInfo,
Expand Down Expand Up @@ -186,11 +186,42 @@ export class MappingComponent implements OnInit, AfterViewInit {
}

exportToExcel() {
let element = document.getElementById('excel-table');
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(element, { raw: true });
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, 'DSOMM - Activities.xlsx');
const table = document.getElementById('excel-table');
if (!table) {
return;
}

const excelXml = `
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta charset="utf-8" />
<!--[if gte mso 9]>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>DSOMM Activities</x:Name>
<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<![endif]-->
</head>
<body>${table.outerHTML}</body>
</html>
`;

const blob = new Blob([excelXml], { type: 'application/vnd.ms-excel' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'DSOMM - Activities.xls';
link.click();
URL.revokeObjectURL(url);

console.log(`${perfNow()}: Mapping: Exported to Excel`);
}

Expand Down
Loading