This project is read-only.

How to rename a worksheet

Feb 7, 2011 at 3:36 PM
Edited Feb 7, 2011 at 3:36 PM
   /// <summary>
   /// Renaming a worksheet in the document
   /// </summary>
   /// <remarks>
   /// Using one instance variable named doc
   /// </remarks>
   /// <param name="oldName">The (current) name of the sheet to rename</param>
   /// <param name="newName">The new sheet name</param>
   private void RenameSheet(string oldName, string newName)
   {
      Sheet sheet = doc.WorkbookPart.Workbook.Descendants().First(s => s.Name == oldName);
      if (sheet != null)
            sheet.Name = newName;
   }