Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Export multiple tables to 1 excel file #64

Open
minhhdl opened this issue May 17, 2017 · 17 comments
Open

Export multiple tables to 1 excel file #64

minhhdl opened this issue May 17, 2017 · 17 comments

Comments

@minhhdl
Copy link

minhhdl commented May 17, 2017

Can we export multi tables to 1 excel file with multi sheets
I need to export a page like this to excel
Please help me, thank you
screencapture-32travel-agent-zcoder-io-statistic-report-1494990495547

@clarketm
Copy link
Owner

clarketm commented May 26, 2017

@minhhuynh96 – Are you asking for the ability to export multiple HTML tables, each as its own sheet, in the same workbook? (can be done for xlsx but NOT xls)

... OR on the same sheet? (is not available but can be added if needed)

@WisdomZheng
Copy link

@clarketm
You said export multiple HTML tables, each as its own sheet, in the same workbook, can be done for xlsx, could you tell me how to set attributes of xlsx to take this action? I've tried as usage mentioned in readme doc, set filename to the same, but export two different workbook.
Many thanks!

@WisdomZheng
Copy link

@clarketm
Sorry for lacking in thinking of my last comment, I have found out the way to export multiple tables to its own sheet in the same workbook, but it seems that the function haven't add to master line. So I define a function using createSheet() to manully create a workbook with multiple sheets.
Thanks for your idea.

@HarrySystems
Copy link

HarrySystems commented Aug 22, 2017

@WisdomZheng can you provide the code you used to export multiple tables?
I'm having the same issue and couldn't figure it out how to make it work...
Here's the code I'm working with.

@WisdomZheng
Copy link

@HarrySystems I have changed the tableexport.js in my fork(TableExport): /src/stable/js/tableexport,js.
I added a function: exportmultisheets() which is according to function: export2file() and createSheet(). The solution is that use createSheet() to create the specific number of sheets you want to export, then add these sheets to workbook and export.
for (each table data){ worksheet = createSheet(table data); workbook.sheets[sheetname] = worksheet; }

Hope it's helpful for you.

@jimbo015
Copy link

I really like tableExport.js -- thanks for writing it!
I'm also interested in downloading multiple tables to a single workbook, each table as its own sheet in the workbook. In my case, each table is in a separate tab (using jquery ui). But I'd love to be able to click once to download all the tables into a single workbook.
Is that possible with the existing code?
I downloaded Wisdom's fork and tried that as well, but not sure how (or if) I need to tell it to create multiple sheets.
Any advice?
Thanks!

@fariskas
Copy link

@WisdomZheng hi , im also looking to export 2 tables as 2 sheets in 1 xlsx file.
I downloaded your fork but i couldnt figure out how to do this too.

Could you perhaps point me and @jimbo015 in the right direction? Many thannks

@coderscoven
Copy link

Can you please guide me on how you did it, @WisdomZheng

@jimbo015
Copy link

jimbo015 commented Dec 12, 2017 via email

@WisdomZheng
Copy link

WisdomZheng commented Dec 22, 2017

@jimbo015 @fariskas @coderscoven
Sorry for reply later due to busying these days.
Firstly, I want to show my issue: export 2 or more tables in the same page to 1 excel file with multiple sheets(each table reflect to 1 sheet):

image

And after export, result shows:
image

image

As for my fork, it just a quick and dirty solution, so I haven't raise a pull request.
Like export2file in tableexport.js, export2file create a workbook and add 1 table in it, my function: exportmultisheet also create a workbook first, but I add all table in the same page to the workbook.
You can define your own export function according to Workbook() and createSheet().

exportmultisheet: function (data, mime, filename, sheetnames, extension, merges={}, cols_width={}) {
                var sheet_data = null;
                var key = extension.substring(1);
                if (_isEnhanced(key)){
                    // create workbook
                    var wb = new this.Workbook();
                    // create sheet for each table in the same page, and add all sheets to workbook
                    for (var i=0; i<data.length; i++){
                        wb.SheetNames.push(this.escapeHtml(sheetnames[i]));
                        var sheet_data = this.createSheet(data[i], merges[sheetnames[i]] || [], cols_width[sheetnames[i]] || []);
                        wb.Sheets[sheetnames[i]] = sheet_data;
                    }
                    var bookType = this.getBookType(key);
                    var wopts = {
                            bookType: bookType,
                            bookSST: false,
                            type: 'binary'
                        },
                        wbout = XLSX.write(wb, wopts);

                    sheet_data = this.string2ArrayBuffer(wbout);
                }
                if (sheet_data){
                    if (_isMobile) {
                        var dataURI = 'data:' + mime + ';' + this.charset + ',' + sheet_data;
                        this.downloadDataURI(dataURI, filename, extension);
                    } else {
                        saveAs(new Blob([sheet_data],
                            {type: mime + ';' + this.charset}),
                            filename + extension, true);
                    }
                }
            }

Usage is similar to export2file() according to: tableexport example exportButtons: false
My demo refer to: export mutiple sheets demo

Importantly, you need to set exportButtons to false, otherwise, when you click the export button, it will call export2file() as default and exportmultisheets() will be disabled. Therefore, set exportButtons to false and define your own export button and its action using exportmultisheets() will work.

Hope my method will help you.

@coderscoven
Copy link

@WisdomZheng, thanks for the assistance. I was able to finally get my code working using your example. Merry Christmas.

@jimbo015
Copy link

jimbo015 commented Dec 23, 2017 via email

@subrat7
Copy link

subrat7 commented Feb 12, 2018

Hi
exportmultisheet is not working in IE10+
please check the image and let me know the changes required.

image

@pfleading
Copy link

export multiple HTML tables, each as its own sheet, in the same workbook? (can be done for xlsx but NOT xls) ok, but how to do that? I am not able to find any proper documentation for that? Also is there way for genrated xlsx file to have the inline css of the html table?

@danielrpp
Copy link

@WisdomZheng thank's for you help!

@amthe22
Copy link

amthe22 commented Mar 12, 2019

@WisdomZheng can you please explain to me how to give the cols_width and css while exporting the table to excel in exportmultisheet.

@tonchi07
Copy link

tonchi07 commented May 1, 2019

How I can export multiple tables in the same sheet. I cant do it. Can i apply css to export?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests