manniru
6/19/2018 - 4:55 PM

React Excel

// import XLSX from 'xlsx';
var xlsx = require('xlsx');
var wb = {
    "Sheets": {
      "Sheet1": {
        "!ref": "A1:C7",
        "A1": {
          "t": "s",
          "v": "This is a merged cell",
          "r": "<t>This is a merged cell</t>",
          "h": "This is a merged cell",
          "w": "This is a merged cell",
          "s": "border: 1px solid black"
        },
        "A2": {
          "t": "s",
          "v": "Bold",
          "r": "<t>Bold</t>",
          "h": "Bold",
          "w": "Bold",
          "s": { "font-weight": "bold"}
        },
        "B2": {
          "t": "s",
          "v": "Italic",
          "r": "<t>Italic</t>",
          "h": "Italic",
          "w": "Italic",
          "s": { "font-style": "italic"}
        },
        "C2": {
          "t": "s",
          "v": "Bold Italic",
          "r": "<t>Bold Italic</t>",
          "h": "Bold Italic",
          "w": "Bold Italic",
          "s": { "font-weight": "bold", "font-style":"italic"}
        },
        "A3": {
          "t": "s",
          "v": "red font",
          "r": "<t>red font</t>",
          "h": "red font",
          "w": "red font",
          "s": { "color": "#F00", color: "red"}// either way is fine
        },
        "B3": {
          "t": "s",
          "v": "red fill",
          "r": "<t>red fill</t>",
          "h": "red fill",
          "w": "red fill",
          "s": { "background-color": "red"}
        },
        "A4": {
          "t": "s",
          "v": "Arial",
          "r": "<t>Arial</t>",
          "h": "Arial",
          "w": "Arial",
          "s": { "font-family": "Arial"}
        },
        "B4": {
          "t": "s",
          "v": "Arial 18pt",
          "r": "<t>Arial 18pt</t>",
          "h": "Arial 18pt",
          "w": "Arial 18pt",
          "s": { "font-family": "arial", "font-size": "18px"}
        },
        "A5": {
          "t": "n",
          "v": 0.618033989,
          "w": "0.618033989"
        },
        "B5": {
          "t": "n",
          "v": 0.618,
          "w": "0.6180",
          "z": "0.000"
        },
        "C5": {
          "t": "n",
          "v": 0.62,
          "w": "62%",
          "z:": "0%"
        },
        "A7": {
          "t": "s",
          "v": "Formula",
          "r": "<t>Formula</t>",
          "h": "Formula",
          "w": "Formula"
        },
        "B7": {
          "t": "n",
          "v": 1.854101966,
          "w": "1.854101966",
          "f": "SUM(A5:C5)"
        },
        "!merges": [
          {
            "s": {
              "c": 0,
              "r": 0
            },
            "e": {
              "c": 2,
              "r": 0
            }
          }
        ]
      }
    },
    "SheetNames": [
      "Sheet1"
    ]
}

// TEST CASE #1:  READ AN EXISTING FILE AND SAVE IT, PRESERVING ITS STYLE
// var workbook = xlsx.readFile('./js-xlsx-example.xlsx');
// xlsx.writeFile(workbook, './out.xlsx');
 
// TEST CASE #2:  CREATE A NEW FILE AND SAVE IT, INCLUDING STYLE


const excel1 = (a) => {
    xlsx.writeFile(wb, './wb.xlsx');

    console.log('this is excel 1: '+a)
}

export default  excel1;