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

Free Support Forum - aspose.com

Copy one sheet from the source workbook to destination workbook

Hello Aspose,
I want to copy the worksheet from source workbook to destination workbook using Aspose c#. The problem is that the source workbook sheet has the formulas in it and want to copy only the data without formulas to the destination workbook. Please help me out with example.

Thanks in Advance

@kiran5388,

You may try to to use Worksheet.Cells.RemoveFormulas() method for your source worksheet in the source workbook before copying it to destination workbook. This will replace underlying formulas with calculated values in the cells. See the following sample code for your reference:
e.g.
Sample code:

            //Instantiate a Workbook object that represents the your source Excel file
            Workbook _workbook = new Workbook("e:\test2\Sample.xlsx");
            //your destination workbook.
            Workbook workbook = new Workbook();
            Clear existing worksheet(s) and add a new sheet named "Report" to it.
            workbook.Worksheets.Clear();
            workbook.Worksheets.Add("Report");
            
             //Remove formulas by calculated results in your source sheet e.g. named "Report" which is to be copied to other workbook.
            _workbook.Worksheets["Report"].Cells.RemoveFormulas();
            
            //Get your source sheet in the source workbook
            Worksheet worksheet = _workbook.Worksheets["Report"];
            //Copy from source to destination
            workbook.Worksheets["Report"].Copy(worksheet);
            //Save your destination file.
            workbook.Save("e:\\test2\\out1.xlsx"); 

Hope, this helps a bit.

Thank you, I will try that.

Hey, it worked thank you very much.

@kiran5388,
You are welcome.