/// <summary> /// Clear text and images from all paragraphs in cell. /// <para/> /// Optional: Delete all paragraph objects. /// Keep in mind, cells with zero paragraphs are considered malformed by Word! /// Also keep in mind, you will lose formatting info (e.g. font). /// <para/> /// Special cases of content other than text or images may not be removed; /// If this becomes a problem, we can develop it. /// </summary> /// <param name="cell"></param> /// <param name="deleteAllParagraphs"></param> public static void CellClear(Cell cell, bool deleteAllParagraphs = false) { // Remove all but first paragraph cell.Paragraphs.Skip(deleteAllParagraphs ? 0 : 1).ToList().ForEach(p => cell.RemoveParagraph(p)); if (!deleteAllParagraphs) { var p = cell.Paragraphs.Last(); if (p.Text.Length > 0) { p.RemoveText(0, p.Text.Length); } } cell.Pictures.ForEach(pic => pic.Remove()); }