Home » excel » Add two DataTables to same excel worksheet in c#

Add two DataTables to same excel worksheet in c#

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to display two data tables one after another in the same excel worksheet in c#.I have tried like this.

var workBook = new XLWorkbook();
workBook.Worksheets.Add(dataSet.table1);
workBook.Worksheets.Add(dataSet.table2);

But it was creating two worksheets in the same excel.
Anyone help me how can i do that?

How to&Answers:

Try to do the following:

workBook.Worksheets.Add(dataSet.table1.Merge(dataSet.table2));  

It would add 1 worksheet with merged data from the 2 tables.