Copy Worksheets between Workbooks

How can i copy a Worksheet between two Workbooks? I am trying to do it like this

var mainWb = new Workbook($"MainPath");
var tempWs= mainWb.Worksheets[2];

var tempWb = new Workbook($"{FilePath}");
tempWb.Worksheets.Add(tempWs);

Why isn’t this working?

@Y.Probst,

Thanks for the code segment.

Please try using Worksheet.Copy() method to copy worksheets b/w workbooks, see the document with example code for your reference:

Hope, this helps a bit.

Thank you @Amjad_Sahi for your answer!

My problem was that i forgot to save the tempWb… my fault I’m sorry…

@Y.Probst,

Good to know that your issue is sorted out now. 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.