sf-i-events 1.0.908 → 1.0.910

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/util.d.ts CHANGED
@@ -21,6 +21,7 @@ declare function getUsermap(): any;
21
21
  declare function getProjectUsermap(): any;
22
22
  declare function setFeatures(features: any): void;
23
23
  declare function getFeatures(): any;
24
+ export declare const downloadExcelFromCSV: (csvString: string, fileName: string | undefined, title: string, projectname: string) => void;
24
25
  declare const exportFunctions: {
25
26
  callApiPresignedDelete: typeof callApiPresignedDelete;
26
27
  callApiPresignedGet: typeof callApiPresignedGet;
@@ -47,6 +48,7 @@ declare const exportFunctions: {
47
48
  setFeatures: typeof setFeatures;
48
49
  getFeatures: typeof getFeatures;
49
50
  getProjectUsermap: typeof getProjectUsermap;
51
+ downloadExcelFromCSV: (csvString: string, fileName: string | undefined, title: string, projectname: string) => void;
50
52
  };
51
53
  export default exportFunctions;
52
54
  //# sourceMappingURL=util.d.ts.map
package/util.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as XLSX from 'xlsx';
1
2
  const validateName = (name) => {
2
3
  if ((name + "").length > 2) {
3
4
  return true;
@@ -437,8 +438,45 @@ function getFeatures() {
437
438
  let features = JSON.parse((_a = localStorage.getItem('features')) !== null && _a !== void 0 ? _a : '["compliances"]');
438
439
  return features;
439
440
  }
441
+ export const downloadExcelFromCSV = (csvString, fileName = 'report.xlsx', title, projectname) => {
442
+ const coverSheetData = [
443
+ [title],
444
+ [],
445
+ ['Project:', projectname],
446
+ ['Date:', getDateTimeStrings(new Date().getTime())],
447
+ ['Classification:', 'Confidential'],
448
+ ['Confidentiality Notice:', 'This document is intended only for the recipient(s) and may contain confidential information. Unauthorized use or disclosure is prohibited. If you are not the intended recipient, please notify the sender and delete this document.']
449
+ ];
450
+ // Create cover sheet
451
+ const coverSheet = XLSX.utils.aoa_to_sheet(coverSheetData);
452
+ // Create CSV data sheet
453
+ const csvSheet = XLSX.read(csvString, { type: 'string' }).Sheets.Sheet1;
454
+ // Create a workbook and append both sheets
455
+ const workbook = XLSX.utils.book_new();
456
+ XLSX.utils.book_append_sheet(workbook, coverSheet, 'Doc');
457
+ XLSX.utils.book_append_sheet(workbook, csvSheet, title);
458
+ // Write workbook to binary
459
+ const wbout = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' });
460
+ const s2ab = (s) => {
461
+ const buf = new ArrayBuffer(s.length);
462
+ const view = new Uint8Array(buf);
463
+ for (let i = 0; i < s.length; i++) {
464
+ view[i] = s.charCodeAt(i) & 0xff;
465
+ }
466
+ return buf;
467
+ };
468
+ const blob = new Blob([s2ab(wbout)], {
469
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
470
+ });
471
+ const link = document.createElement('a');
472
+ link.href = URL.createObjectURL(blob);
473
+ link.download = fileName;
474
+ document.body.appendChild(link);
475
+ link.click();
476
+ document.body.removeChild(link);
477
+ };
440
478
  const exportFunctions = {
441
- callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap, setFeatures, getFeatures, getProjectUsermap
479
+ callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap, setFeatures, getFeatures, getProjectUsermap, downloadExcelFromCSV
442
480
  };
443
481
  export default exportFunctions;
444
482
  //# sourceMappingURL=util.js.map