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

@legtech/export

v2.0.0

Published

Functions to format an html table and data into json for export to Excel

Downloads

10

Readme

Functions to format an html table and data into json for export to Excel

Steps to use:

  1. Put the following in your html page or javascript:
WSLApp.Export.init();	
  1. Include an export button in the following format:
<input type="button" class="btn btn-primary exportTableButton" value="Export" disabled data-export-table="[id of the table you want to export]" data-export-url="@Url.Action("[ACTION NAME]","[CONTROLLER NAME]")"/>
  1. Include a controllor action to post the data too - for example:
[HttpPost]
public ActionResult ExportSearchResults(string exportSearchResultsData)
{
    if (exportSearchResultsData == null)
        return new EmptyResult();

    var searchResults = JsonConvert.DeserializeObject<IEnumerable<IEnumerable<string>>>(exportSearchResultsData);

    var csv = new StringBuilder();

    foreach (var rowResult in searchResults)
    {
        var quotedRow = rowResult.Select(p => "\"" + p.Replace("\"", "\"\"") + "\"");
        var row = string.Join(",", quotedRow);
        csv.AppendLine(row);
    }

    // This is a lot faster than using the File action.  See http://stackoverflow.com/questions/1928494/mvc-action-taking-a-long-time-to-return.

    Response.ContentType = "text/csv";
    Response.Headers.Add("Content-Disposition", "attachment;filename=SearchResults.csv");
    var csvBytes = Encoding.UTF8.GetBytes(csv.ToString());
    Response.Body.WriteAsync(csvBytes,0, csvBytes.Length );

    return new EmptyResult();
}

Additional Options:

  1. You can add a Title for a table, which will appear above the table in the first column. To set a title add the following attribute to a table: data-export-title="Your Title Here"
  2. You can specify mulitple tables for export by using a class instead of a table id. The tables will show up sequentially with a single line between them. To target multiple tables use the following on the export button data-export-table="[css class on the tables you want to export]"
  3. You can have the exporter ignore child elements within a table cell. To have it ignore child elements add data-trim-children="true" to the necessary table cell. For example, if your cell looks like TextSome Icon and you would like to just export 'Text'.
  4. You can override the text being exported from a cell. If set, the value of data-export-text will be used instead of the content of the cell. To use this, add attribute data-export-text="Text to export" to any td or th.