ronaldkwandy

Untitled

May 12th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2.  
  3. // import Spreadsheet from 'x-data-spreadsheet';
  4.  
  5. import * as $ from 'jquery';
  6.  
  7. // using external js modules in Angular
  8. declare var Slick: any;
  9.  
  10. @Component({
  11.   selector: 'app-jexcel',
  12.   templateUrl: './jexcel.component.html',
  13.   styleUrls: ['../../../../../../node_modules/bootstrap/dist/css/bootstrap.min.css']
  14. })
  15. export class JExcelComponent implements OnInit, OnDestroy {
  16.  
  17.   // public data = {
  18.   //   rows: {
  19.   //     0: {
  20.   //       cells: {
  21.   //         0: { text: 'Google' }
  22.   //       }
  23.   //     },
  24.   //     1: {
  25.   //       cells: {
  26.   //         0: { text: 'Apple' }
  27.   //       }
  28.   //     },
  29.   //     2: {
  30.   //       cells: {
  31.   //         0: { text: 'Yahoo' }
  32.   //       }
  33.   //     }
  34.   //   }
  35.   // };
  36.  
  37.   public options: any = {};
  38.  
  39.   constructor() { }
  40.  
  41.   ngOnInit() {
  42.     // /* generate worksheet */
  43.     // const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(this.data);
  44.  
  45.     // /* generate workbook and add the worksheet */
  46.     // const wb: XLSX.WorkBook = XLSX.utils.book_new();
  47.     // XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
  48.  
  49.     // /* save to file */
  50.     // XLSX.writeFile(wb, 'SheetJS.xlsx');
  51.     // this.options = {
  52.     //   showToolbar: false,
  53.     //   showGrid: true,
  54.     //   showContextmenu: false,
  55.     //   view: {
  56.     //     height: () => document.documentElement.clientHeight,
  57.     //     width: () => document.documentElement.clientWidth
  58.     //   },
  59.     //   row: {
  60.     //     len: 20
  61.     //   },
  62.     //   col: {
  63.     //     len: 4
  64.     //   },
  65.     //   style: {
  66.     //     bgcolor: '#ffffff',
  67.     //     align: 'left',
  68.     //     valign: 'middle',
  69.     //     textwrap: false,
  70.     //     strike: false,
  71.     //     underline: false,
  72.     //     color: '#0a0a0a',
  73.     //     font: {
  74.     //       name: 'Helvetica',
  75.     //       size: 10,
  76.     //       bold: false,
  77.     //       italic: false,
  78.     //     }
  79.     //   }
  80.     // };
  81.     // const s = new Spreadsheet('#x-spreadsheet-demo', this.options)
  82.     //   .loadData(this.data) // load data
  83.     //   .change(data => {
  84.     //     console.log('data : ', data);
  85.     //     console.log('data : ', this.data);
  86.     //   });
  87.  
  88.     let grid;
  89.     const columns = [
  90.       { id: 'title', name: 'Title', field: 'title', editor: Slick.Editors.Text },
  91.       { id: 'duration', name: 'Duration', field: 'duration', editor: Slick.Editors.Text },
  92.       { id: '%', name: '% Complete', field: 'percentComplete', editor: Slick.Editors.Text },
  93.       { id: 'start', name: 'Start', field: 'start', editor: Slick.Editors.Text },
  94.       { id: 'finish', name: 'Finish', field: 'finish', editor: Slick.Editors.Text },
  95.       { id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', editor: Slick.Editors.Text }
  96.     ];
  97.  
  98.     const options = {
  99.       enableCellNavigation: true,
  100.       enableColumnReorder: false,
  101.       editable: true,
  102.       enableAddRow: true,
  103.       asyncEditorLoading: false,
  104.       autoEdit: false
  105.     };
  106.  
  107.     const data = [];
  108.  
  109.     $(document).ready(() => {
  110.       for (let i = 0; i < 500; i++) {
  111.         const d = (data[i] = {});
  112.         d['title'] = 'Task ' + i;
  113.         d['description'] = 'This is a sample task description.\n  It can be multiline';
  114.         d['duration'] = '5 days';
  115.         d['percentComplete'] = Math.round(Math.random() * 100);
  116.         d['start'] = '01/01/2009';
  117.         d['finish'] = '01/05/2009';
  118.         d['effortDriven'] = (i % 5 === 0);
  119.       }
  120.  
  121.       grid = new Slick.Grid('#myGrid', data, columns, options);
  122.  
  123.       // grid.setSelectionModel(new Slick.CellSelectionModel());
  124.       // grid.onAddNewRow.subscribe((e, args) => {
  125.       //   const item = args.item;
  126.       //   grid.invalidateRow(data.length);
  127.       //   data.push(item);
  128.       //   grid.updateRowCount();
  129.       //   grid.render();
  130.       // });
  131.  
  132.       // grid.onDblClick.subscribe((e, args) => {
  133.       //   console.log('e : ', e);
  134.       //   console.log('args : ', args);
  135.       // });
  136.     });
  137.   }
  138.  
  139.   ngOnDestroy() { }
  140.  
  141.   // public onFileChange(evt: any) {
  142.   //   /* wire up file reader */
  143.   //   const target: DataTransfer = <DataTransfer>(evt.target);
  144.   //   if (target.files.length !== 1) { throw new Error('Cannot use multiple files'); }
  145.   //   const reader: FileReader = new FileReader();
  146.   //   reader.onload = (e: any) => {
  147.   //     /* read workbook */
  148.   //     const bstr: string = e.target.result;
  149.   //     const wb: XLSX.WorkBook = XLSX.read(bstr, { type: 'binary' });
  150.  
  151.   //     /* grab first sheet */
  152.   //     const wsname: string = wb.SheetNames[0];
  153.   //     const ws: XLSX.WorkSheet = wb.Sheets[wsname];
  154.  
  155.   //     /* save data */
  156.   //     this.data = (XLSX.utils.sheet_to_json(ws, { header: 1 }));
  157.   //   };
  158.   //   reader.readAsBinaryString(target.files[0]);
  159.   // }
  160.  
  161.   public test() {
  162.     // this.options.row.len = this.options.row.len + 1;
  163.     // console.log('options : ', this.options);
  164.     // new Spreadsheet('#x-spreadsheet-demo', this.options)
  165.     //   .loadData(this.data);
  166.   }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment