TableExport icon indicating copy to clipboard operation
TableExport copied to clipboard

Export multiple tables to 1 excel file

Open minhhdl opened this issue 7 years ago • 17 comments

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

minhhdl avatar May 17 '17 03:05 minhhdl

@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)

clarketm avatar May 26 '17 19:05 clarketm

@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 avatar Jul 13 '17 09:07 WisdomZheng

@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.

WisdomZheng avatar Jul 14 '17 06:07 WisdomZheng

@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.

HarrySystems avatar Aug 22 '17 22:08 HarrySystems

@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.

WisdomZheng avatar Aug 24 '17 10:08 WisdomZheng

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!

jimbo015 avatar Oct 16 '17 23:10 jimbo015

@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

fariskas avatar Nov 10 '17 14:11 fariskas

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

coderscoven avatar Dec 12 '17 19:12 coderscoven

I would love to know, too! Thanks for any help you can give! Jim

On Tue, Dec 12, 2017 at 11:15 AM coderscoven [email protected] wrote:

Can you please guide me on how you did it, @WisdomZheng https://github.com/wisdomzheng

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clarketm/TableExport/issues/64#issuecomment-351160960, or mute the thread https://github.com/notifications/unsubscribe-auth/AUDWCYJO7oGFWvsRyaZh4950bkV_n9F1ks5s_tDjgaJpZM4NdUvR .

-- -- sent from my mobile phone.

jimbo015 avatar Dec 12 '17 21:12 jimbo015

@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.

WisdomZheng avatar Dec 22 '17 10:12 WisdomZheng

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

coderscoven avatar Dec 23 '17 11:12 coderscoven

Thank you for sending this! I'll try it as soon as I return from traveling. Jim

On Fri, Dec 22, 2017 at 6:42 AM, Wisdom Zheng [email protected] wrote:

@jimbo015 https://github.com/jimbo015 @fariskas https://github.com/fariskas @coderscoven https://github.com/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: image] https://user-images.githubusercontent.com/28619254/34295087-634615f2-e746-11e7-8a4c-b7d9ed5d9d45.png

And after export, result shows: [image: image] https://user-images.githubusercontent.com/28619254/34295116-87add092-e746-11e7-8ea2-a63d69e25a98.png

[image: image] https://user-images.githubusercontent.com/28619254/34295132-91923706-e746-11e7-96dc-dffd3fcf8d35.png

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 https://tableexport.v3.travismclarke.com/examples/exportButtons.html My demo refer to: export mutiple sheets demo https://jsfiddle.net/WisdomZheng/Law5gp44/

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

Hope my method will help you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/clarketm/TableExport/issues/64#issuecomment-353572314, or mute the thread https://github.com/notifications/unsubscribe-auth/AUDWCSShUzDWZjVFSRHcnXd_h3BYVfzGks5tC4eSgaJpZM4NdUvR .

jimbo015 avatar Dec 23 '17 12:12 jimbo015

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

image

subrat7 avatar Feb 12 '18 15:02 subrat7

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?

pfleading avatar Feb 14 '18 13:02 pfleading

@WisdomZheng thank's for you help!

danielrpp avatar Apr 22 '18 01:04 danielrpp

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

amthe22 avatar Mar 12 '19 07:03 amthe22

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

tonchi07 avatar May 01 '19 20:05 tonchi07