question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for excel exporting

See original GitHub issue

We need an additional property in downloadOptions for user to specify csv or excel format when exporting only filtered data.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
jaime-ezcommented, Nov 9, 2020

Hi, I’m just gonna leave here a comment with a solution for exporting excel files in case anyone finds it useful:

import { saveAs } from 'file-saver'
import { write, utils } from 'xlsx'

// on the table component
                      onDownload: (buildHead, buildBody, columns, values) => {
                        const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'
                        const fileExtension = '.xlsx'
                        // build the json, this is one way to do it
                        const json = reduce(values, (result, val) => {
                          const temp = {}
                          forEach(val.data, (v, idx) => {
                            temp[columns[idx].name] = v
                          })
                          result.push(temp)
                          return result
                        }, [])

                        const fileName = `$yourFileName`
                        const ws = utils.json_to_sheet(json)
                        const wb = { Sheets: { 'data': ws }, SheetNames: ['data'] }
                        const excelBuffer = write(wb, { bookType: 'xlsx', type: 'array' })
                        const data = new Blob([excelBuffer], { type: fileType })
                        saveAs(data, fileName + fileExtension)
                        // cancel default  CSV download from table
                        return false
                     }

If this should be somehwere else please let me know to make a pull.

Best

2reactions
jaime-ezcommented, Sep 13, 2021

Oh yes sorry, I was using lodash’s reduce. Thanks for the label customization

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export data to Excel - Microsoft Support
Run the export operation · Double-click the form to open it. · Right-click the form, and then click Datasheet View. If this option...
Read more >
Export linked data source information to Excel
Open the Linked Table Manager dialog in Access 2016 or later by clicking External Data > Linked Table Manager. Select the linked data...
Read more >
Export your project to Excel - Microsoft Support
Export your project data to Excel for in-depth data analysis and create visual reports by using Excel PivotTables, charts, and other features.
Read more >
Export to Excel from SharePoint or Lists - Microsoft Support
Export to an Excel workbook ... From the command bar of the list, select Export > Export to Excel. The Export options for...
Read more >
Export an external list to Excel - Microsoft Support
Export the external list to Excel ... Select List, and then select Export to Excel. By default, this capability is enabled on external...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found