SheetJS js-xlsx use

js-xlsx official document: https://sheetjs.gitbooks.io/docs/#sheetjs-js-xlsx

npm xlsx Address: https://www.npmjs.com/package/xlsx

Official website: https://sheetjs.com/opensource

 

First, the installation or the introduction:

 
 
In the browser, simply add a script tag: 
<Script lang = "JavaScript" src = "dist / xlsx.full.min.js"> </ Script> 

using npm: 
$ npm install XLSX 

use
Bower:
$ Bower install JS -xlsx

* Import AS XLSX from  ' XLSX ' ;   // Data Import Export dependent required

With angular, for example:

exportExcle () { 

       // use XLSX.utils.aoa_to_sheet (excleData); 
        // const excleData = [ 
        @      [ 'Monday', "Tuesday", "Wednesday", "Thursday", "Friday"], 
        //      [ 'language', 'mathematics',' history ',' political ',' English '], 
        //      [' mathematics', 'mathematical', 'political', 'English', 'English'], 
        //      [ ' political ',' English ',' history ',' political ',' mathematics '], 
        // ]; 

       // use XLSX.utils.json_to_sheet (excleData); 
        const excleData = [ 
            {Monday: ' language 'on Tuesday:' mathematics', Wednesday: 'history', Thursday: 'politics', on Friday:' English ' }, 
            {Monday:'Mathematics', Tuesday: 'Mathematics', Wednesday: 'political', Thursday: 'English', Friday: 'English' }, 
            {Monday: 'Politics', on Tuesday: 'English', Wednesday: 'History' Thursday: 'politics', on Friday: 'Mathematics'} 
        ]; 

        // set the table style, column width cols! 
        Const Options = {
           'cols!' : [ 
                {WPX: 100 }, 
                {WPX: 100 }, 
                {WPX: 100 }, 
                {WPX: 100 }, 
                { WPX: 100 }, 
        ]}; 
       // embodiment worksheet prepared there are many objects in an array, and Example 
        // const worksheet: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet (excleData); 
        const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet (excleData); 

       //Use the specified cell as a starting point to insert data, r: OK, c: columns, details Tell me what network documentation 
        // XLSX.utils.sheet_add_aoa (Worksheet, [[ "Mathematics", "language"], [ "political", "language "], [" history "," politics "],], {Origin: {R & lt: 2, C:}}. 5); 
        Worksheet [ '! cols'] = Options [ '! cols' ]; 

        // Create a workbook 
        const workbook: XLSX.WorkBook = XLSX.utils.book_new (); 

        / * Add the worksheet to the workbook * / 
        XLSX.utils.book_append_sheet (workbook, worksheet, 'Sheet1' );
         / * output sheet, by the determines the output format of the file name * / 
        XLSX.writeFile (Workbook, 'table row Chamber .xlsx' ); 
    }

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lvsk/p/11970747.html