This project is read-only.

Removing a worksheet, howto:

Jun 28, 2010 at 8:35 AM
Edited Jun 28, 2010 at 9:11 AM

/// <summary>
/// Deletes a worksheet from the document
/// </summary>
/// <remarks>
/// Uses one instance variable, named doc.
/// </remarks>
/// <param name="sheetName">The name of the sheet to remove.</param>
/// <returns>If the worksheet existed before.</returns>
public bool RemoveWorksheet(string sheetName)
{
    IEnumerable<Sheet> sheets = doc.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == sheetName);
    if (sheets.Count() == 0)
    {
        return false;
    }

    doc.WorkbookPart.DeletePart(sheets.First().Id);
    doc.WorkbookPart.Workbook.Sheets.RemoveChild<Sheet>(sheets.First());
    doc.WorkbookPart.Workbook.Save();
    return true;
}

Jul 9, 2010 at 10:16 PM
This has been tested and added to the SpreadsheetWriter class. Many thanks.
Jul 16, 2010 at 8:35 AM
Way to go!