We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy worksheet to the end of another worksheet

I would like to copy a number of worksheets from one workbook to a another worksheet in a different workbook.

I want to add the source worksheet each time to the end of the destination worksheet.
For example if the destination worksheet last row in use (after the first copy) is 20 so the second copy (the next worksheet) would go in the row 22 and so forth.

Is it possible?
How would i do that?

Thanks in advance


Please see the following documentation article for your reference on how to combine multiple worksheets into a single worksheet:

Hope, this helps a bit.

Thank you.
thank you for your replay.
This is good but it's a little different from what i want to do.

I have 2 workbook with 2 worksheets, (sheet1, sheet2)
All the tow workbook have exactly 2 worksheets with the same name: sheet1, sheet2

In the destination file i already have tow empty worksheets named: sheet1, sheet2

So what i need is to be in the destination workbook is this:
1: all data from the "first" worksheet from the 2 source workbook in the "sheet1" worksheet.
2: same for "sheet2" worksheet

this is link for the example file:
source-01, source-02, destination

about the link that you provided:

      Range destRange = destSheet.Cells.CreateRange
(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn,
            sourceRange.RowCount, sourceRange.ColumnCount);

what i want to do is to copy "destRange" to a specific worksheet in the destination file.

I hope that now its more clear.
Thank you again

found this

very close but the line:
is erase everithing.
i need to add.

Thank you

Hi Tomas,

Please try the following piece of code for your requirement. Please note, the code generates the destination workbook from scratch. You may easily modify the code to copy the data onto an existing spreadsheet. Please feel free to contact us back in case you face any difficulty.


var book1 = new Workbook(“C:/temp/source_01.xlsx”);
var book1Sheet1 = book1.Worksheets[0];
var rangeBook1Sheet1 = book1Sheet1.Cells.CreateRange(0, 0, book1Sheet1.Cells.MaxDataRow + 1, book1Sheet1.Cells.MaxDataColumn + 1);
var book1Sheet2 = book1.Worksheets[1];
var rangeBook1Sheet2 = book1Sheet2.Cells.CreateRange(0, 0, book1Sheet2.Cells.MaxDataRow + 1, book1Sheet2.Cells.MaxDataColumn + 1);

var book2 = new Workbook(“C:/temp/source_02.xlsx”);
var book2Sheet1 = book2.Worksheets[0];
var rangeBook2Sheet1 = book2Sheet1.Cells.CreateRange(0, 0, book2Sheet1.Cells.MaxDataRow + 1, book2Sheet1.Cells.MaxDataColumn + 1);
var book2Sheet2 = book2.Worksheets[1];
var rangeBook2Sheet2 = book2Sheet2.Cells.CreateRange(0, 0, book2Sheet2.Cells.MaxDataRow + 1, book2Sheet2.Cells.MaxDataColumn + 1);

var book = new Workbook();
var sheet1 = book.Worksheets[0];

//copying range from first workbook first sheet
sheet1.Cells.CreateRange(rangeBook1Sheet1.FirstRow, rangeBook1Sheet1.FirstColumn, rangeBook1Sheet1.RowCount, rangeBook1Sheet1.ColumnCount).Copy(rangeBook1Sheet1);
//copying range from second workbook first sheet
sheet1.Cells.CreateRange(sheet1.Cells.MaxDataRow + 2, rangeBook2Sheet1.FirstColumn, rangeBook2Sheet1.RowCount, rangeBook2Sheet1.ColumnCount).Copy(rangeBook2Sheet1);

var sheet2 = book.Worksheets[book.Worksheets.Add()];

//copying range from first workbook second sheet
sheet2.Cells.CreateRange(rangeBook1Sheet2.FirstRow, rangeBook1Sheet2.FirstColumn, rangeBook1Sheet2.RowCount, rangeBook1Sheet2.ColumnCount).Copy(rangeBook1Sheet2);
//copying range from second workbook second sheet
sheet2.Cells.CreateRange(sheet2.Cells.MaxDataRow + 2, rangeBook2Sheet2.FirstColumn, rangeBook2Sheet2.RowCount, rangeBook2Sheet2.ColumnCount).Copy(rangeBook2Sheet2);


This is work!
Thank you very much!


Good to know that the suggested code works fine for your requirements. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.