[]
To copy the rows of a sheet from one book to a second book, complete the following steps:
Add a reference to C1.WPF.Excel.dll.
Load an existing book.
C1XLBook wb = new C1XLBook();
wb.Load(@"C:\test.xlsx");
Create a new workbook with an XLSheet named Test.
C1XLBook xb = new C1XLBook();
xb.Sheets.Add("Test");
Copy each row from the sheet of the existing book to the new workbook Test sheet.
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;
}
}
Save and open the new workbook.
// Save and open the file
xb.Save(@"C:\test2.xlsx");
System.Diagnostics.Process.Start(@"C:\test2.xlsx");
Open the new book. The rows from the first book have been added to the new book.