Reputation: 524
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?
Upvotes: 1
Views: 4397
Reputation: 1
You should specify cell where should starts table:
worksheet.Cell(1, 1).InsertTable(dataTable);
worksheet.Cell(dataTable.Rows.Count + 2, 1).InsertTable(secondTable);
More inforamtion about ClosedXML: https://github.com/ClosedXML/ClosedXML/wiki/Inserting-Tables
Upvotes: 0
Reputation: 61
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.
Upvotes: 3