Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
How do I copy a Worksheet from one Workbook to another Workbook?
posted

We are generating SQL Server reports and rendering them to Excel format.  Each report creates a new Workbook.   We need to be able to open workbook1 and workbook2 and then copy a sheet1 from workbook2 into workbook1 as the last sheet.

We can do this using the Excel object model, but would prefer to use the Infragistics.Excel so that Office does not have to be installed on a server.

I have looked over the Infragistics.Excel documentation and do not see any API support for this. 

Any help would be appreciated. 

Kent

 

 

Parents Reply
  • 44743
    posted in reply to Mihir

    No, this feature is currently not implemented. You can submit a feature request for this and that will increase the likelihood that it will get implemented.

    As for manually copying over data, I suggest using and foreach statement to iterate through the Worksheet.Rows collection. This will only return the rows which have been accessed, which means they probably have cell data and/or formatting. For each row iterated, copy over the row's height and formatting and then iterate the row's Cells collection, again using a foreach statement, because that will only return the cells with data and/or formatting. For each cell iterated, copy over the cell's formula if present. Otherwise, copy over the value. Then copy over the cell's CellFormat using the SetFormatting method listed above. After iterating the Rows collection, also iterate the Worksheet.Columns collection (again using a foreach statement). Copy over the formatting and width of each column.

Children