npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

excel-operations-node

v1.0.0

Published

Nodel Excel file manipulator that lets you perform operations on spreadsheets (add row, pivot table, etc). You can write your new transformed spreadsheets to files, and serve your spreadsheets from a server using NodeJS. Way faster than excel.

Downloads

13

Readme

Built on top of the excellent work of mgcrea and node-xlsx (https://www.npmjs.com/package/node-xlsx)

Note: This library only handles single sheet XLS files - put all your data in one sheet before using this if you don't want to get an error

To use this library, you must have your column labels defined in the first row of your xls file

To install the library

	var xlsHelper = require("node-excel-operations");

To read your file-- and create a helper to perform operations on your file -- pass in absolute directory path to a new instance of the library

	var xls = new xlsHelper(__dirname + "/sampleData.xlsx");

Helper functions available to you:

write(filepath): writes the file (and any modifications you made) to a new xls file at provided filepath

	xls.write(__dirname + "/newfile.xls") // this will produce a new xls file, if you made any changes to the file using functions below, the changes are reflected on the written file

seeColumnNames(): returns array of columnNames(defined as elements in first row in xls), also logs columnNames to the console

addColumn(columnName,callback) : adds a new Column to the end of the sheet under the name given in columnName. The callback defines the values present in the new column. The only argument passed to the callback is an object with all of your column names as keys. Return the mathematical result you want to put into your new column in your callback.

For example, if you have a column called "oldweight" and a column called "newweight", here is how you would add a column "old weight-new weight", which would have the difference of the neweight and oldweight columns, to your sheet

xls.addColumn("Old Weight - New Weight Column",function(data){
	return data.oldweight - data.newweight;
}) 

To add the sum of the two columns you would do this:

xls.addColumn("Old Weight + New Weight Column",function(data){
	return data.oldweight + data.newweight;
}) 

addColumnSimple(columnName,calcString): same as addColumn above, but simpler. The first argument is the name that will be given to your new column. The second argument is a string describing the mathematical result you want to put in your new column. Example:

xls.addColumnSimple("Old Weight + New Weight Column","oldweight + newweight");

addRow(rowName,cb): adds a new row to the bottom of your sheet. The row will be given a label based on waht you pass in as row name. Similar to addColumn,above, addRow takes a callback that defines how you want to combine the elements in each column to get your new row. To get the sum of each column, you would do this:

xls.addRow("Sum",function(a,b){return a + b;});

pivotTable(function,colToOperateOn,rowlabel,columnlabel): mimics Excel pivot tables (http://www.excel-easy.com/data-analysis/pivot-tables.html)

The first argument is the function that defines what operation you want to do on the value in each row that you are "pivoting". The second is the name of the column you want to pivot. The third is the name of the column whose values you want to put in the row of your table. The fourth is the name of the row whose values you want to put in the columns of your table

For example you could run the code below to create a pivot table where you see the sum of the weight column for all combinations of ages and sex

	xls.pivotTable(function(a,b){return a+b},"weight","age","sex")

writepivotTable(directory): writes the pivotTable created with the pivotTable function to the file at the path 'directory'

printToHTML(): prints the table -- with any modifications -- to an HTML string that will create a table with your data in a browser