# Copying Rows from One Book to Another (WPF)

## Content



To copy the rows of a sheet from one book to a second book, complete the following steps:

1.  Add a reference to C1.WPF.Excel.dll.
2.  Load an existing book.
    
    ```csharp
    C1XLBook wb = new C1XLBook();
    wb.Load(@"C:\test.xlsx");
    ```
    
3.  Create a new workbook with an **XLSheet** named **Test**.
    
    ```csharp
    C1XLBook xb = new C1XLBook();
    xb.Sheets.Add("Test");
    ```
    
4.  Copy each row from the sheet of the existing book to the new workbook **Test** sheet.
    
    ```csharp
    XLSheet source = wb.Sheets[0];
                XLSheet dest = xb.Sheets["Test"];
                for (int row = 0; row <= source.Rows.Count - 1; row++)
                {
                    for (int col = 0; col <= source.Columns.Count - 1; col++)
                    {
                        dest[row, col].Value = source[row, col].Value;
                    }
                }
    ```
    
5.  Save and open the new workbook.
    
    ```csharp
    // Save and open the file
    xb.Save(@"C:\test2.xlsx");
    System.Diagnostics.Process.Start(@"C:\test2.xlsx");
    ```
    
6.  Open the new book. The rows from the first book have been added to the new book.