# @legtech/export

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

Latest version **2.0.0** (published 2022-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @legtech/export
pnpm add @legtech/export
yarn add @legtech/export
bun add @legtech/export
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-03-15 |
| First published | 2019-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kevinewig, matthew.edwards.legtech, frank.hoffman, bzeitner |

## Links

- npm: https://www.npmjs.com/package/@legtech/export
- Repository: https://dev.azure.com/waleg/Architecture/_git/NpmPackages?path=/export
- Homepage: https://dev.azure.com/waleg/Architecture/_wiki/wikis/Architecture.wiki/313/export
- npm.io page: https://npm.io/package/@legtech/export

## Dependencies (2)

- [jquery](https://npm.io/package/jquery.md) >=1.0.0
- [@legtech/namespace](https://npm.io/package/@legtech/namespace.md) >=1.0.0

## Recent versions

- 2.0.0 (latest) — 2022-03-15
- 1.0.2 — 2022-03-12
- 1.0.1 — 2019-11-14
- 1.0.0 — 2019-03-27

## 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:
```javascript
WSLApp.Export.init();	
```
2. Include an export button in the following format:
```html
<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]")"/>
```
3. Include a controllor action to post the data too - for example:
```cs
[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"
1. 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]"
1. 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 <td>Text<i>Some Icon</i></td> and you would like to just export 'Text'.
1. 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.

---
_Source: https://npm.io/package/@legtech/export · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
