Excel for WPF | ComponentOne
C1.WPF.Excel Namespace / XLSheet Class / Clone Method
Example

In This Topic
    Clone Method (XLSheet)
    In This Topic
    Creates a copy of this sheet.
    Syntax
    'Declaration
     
    
    Public Function Clone() As XLSheet
    public XLSheet Clone()

    Return Value

    A new XLSheet object with the same contents and formatting as this sheet.
    Remarks

    After cloning a sheet, you must rename it and then add it to the book (duplicate names are not allowed).

    This method is useful for applications that generate books with a large number of similar sheets.

    Example
    The code below loads a book that contains a template sheet, creates 12 copies of that sheet, removes the template sheet, then saves the file with a new name.
    // load book with template sheet
    _c1xl.Load(@"c:\temp\template.xls");
                
    // create 12 copies of the template sheet
    XLSheet templateSheet = _c1xl.Sheets["Template"];
    for (int month = 1; month <= 12; month++)
    {
      XLSheet newSheet = templateSheet.Clone();
      newSheet.Name = month.ToString(); // rename clone
      newSheet[0,0].Value = month;      // make changes
      _c1xl.Sheets.Add(newSheet);       // add clone to book
    }
                
    // remove the template sheet and save with new name
    _c1xl.Sheets.Remove("Template");
    _c1xl.Save(@"C:\temp\expense_report.xls");
    See Also