GithubHelp home page GithubHelp logo

Comments (2)

daveRanjan avatar daveRanjan commented on July 21, 2024

@pat310 Do we have any update on this? I need to provide data in excel (csv can also work) format.

from quick-pivot.

1F987 avatar 1F987 commented on July 21, 2024

@daveRanjan @vijaysebastian : You can use this cool project https://github.com/exceljs/exceljs to make an Excel file.

Example in nodejs :

const ExcelJS = require('exceljs');
const Pivot = require('quick-pivot');

// Self-Executing Anonymous Functions
(async function(){

const wb = new ExcelJS.Workbook();
wb.creator = 'Example';
const sheet2 = wb.addWorksheet('Test',
    {
        views: [
            {state: 'frozen', ySplit: 1}
        ],
        properties:
            {
                tabColor:
                    {argb: 'FFC0000'}
            }
    }
);

// Load your data, make your pivot table
// For example


const dataArray = [
    ['name', 'gender', 'house', 'age'],
    ['Jon', 'm', 'Stark', 14],
    ['Arya', 'f', 'Stark', 10],
    ['Cersei', 'f', 'Baratheon', 38],
    ['Tywin', 'm', 'Lannister', 67],
    ['Tyrion', 'm', 'Lannister', 34],
    ['Joffrey', 'm', 'Baratheon', 18],
    ['Bran', 'm', 'Stark', 8],
    ['Jaime', 'm', 'Lannister', 32],
    ['Sansa', 'f', 'Stark', 12]
];

const rowsToPivot = ['name'];
const colsToPivot = ['house', 'gender'];
const aggregationDimension = 'age';
const aggregator = 'sum';

const pivot = new Pivot(dataArray, rowsToPivot, colsToPivot, aggregationDimension, aggregator);

pivot.data.table.forEach(line => {
    // rowHeader in bold for example
    switch(line.type) {
        case 'rowHeader' :
            sheet2.addRow(line.value).font = {
                bold: true
            }
            break;
        case 'aggregated':
            sheet2.addRow(line.value).font = {
                bold: true
            }
            break;
        default:
            sheet2.addRow(line.value)
    }
})

await wb.xlsx.writeFile('your-physical-file.xlsx');

})();

from quick-pivot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.