table-to-excel icon indicating copy to clipboard operation
table-to-excel copied to clipboard

One File, Multiple Sheets Per Table

Open Markseemus opened this issue 4 years ago • 3 comments

Hi, how can I include multiple tables in one file separated by sheets?

I already tried using two TableToExcel functions with different IDs and sheet names with the same file name, but it ended up downloading two separate files instead.

Here's what I did:

let button = document.querySelector("#button-excel");

button.addEventListener("click", e => {
  TableToExcel.convert(document.querySelector("#table1"), {
  	name: "FileName.xlsx",
  	sheet: {
  		name: "Sheet 1"
  	}
  });
  TableToExcel.convert(document.querySelector("#table2"), {
  	name: "FileName.xlsx",
  	sheet: {
  		name: "Sheet 2"
  	}
  });
});

Are there any functions that can be used to make this possible?

Markseemus avatar Aug 15 '19 05:08 Markseemus

Hi Lee,

Sorry for the late response. I've tried this and it works perfectly now. Thank you!

On Wed, Aug 21, 2019 at 2:32 AM Lee [email protected] wrote:

I was able to achieve this by wrapping the two tables in my html with a div and then using that div as the reference point. Something like the below.

...
...

TableToExcel.convert(document.querySelector("#wrapper"));

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/linways/table-to-excel/issues/23?email_source=notifications&email_token=AE2QGU7EGZ5VTMJJZARARP3QFQ2E3A5CNFSM4IL3IPUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XH7PY#issuecomment-523141055, or mute the thread https://github.com/notifications/unsubscribe-auth/AE2QGU7JAH5EEFLAOOZCEXLQFQ2E3ANCNFSM4IL3IPUA .

Markseemus avatar Aug 29 '19 03:08 Markseemus

@Markseemus please One File, Multiple Sheets Per Table?

parkashkumaar avatar Sep 25 '19 11:09 parkashkumaar

For now, you can use the following workaround to add multiple sheets to a file:

table1 = document.getElementById("simpleTable1");
table2 = document.getElementById("simpleTable2");
book = TableToExcel.tableToBook(table1, {sheet:{name:"sheet1"}});
TableToExcel.tableToSheet(book, table2, {sheet:{name:"sheet2"}});
TableToExcel.save(book, "test.xlsx")

Will accomodate multiple sheets into the convert function.

rohithb avatar Sep 28 '19 18:09 rohithb