static void FixInvalidSlideLayouts(Presentation presentation) { Console.WriteLine("Fixing the invalid slide layouts..."); var layoutMappings = new Dictionary <string, string> { { "Presentation Title Slide", "Presentation Title Slide" }, { "Section Title Slide", "Section Title Slide" }, { "Section Slide", "Section Title Slide" }, { "Title Slide", "Section Title Slide" }, { "Заглавен слайд", "Section Title Slide" }, { "Demo Slide", "Demo Slide" }, { "Live Exercise Slide", "Section Title Slide" }, { "Background Slide", "Section Title Slide" }, { "Important Concept", "Important Concept" }, { "Important Example", "Important Example" }, { "Table of Content", "Table of Contents" }, { "Table of Contents", "Table of Contents" }, { "Comparison Slide", "Comparison Slide" }, { "Title and Content", "Title and Content" }, { "Заглавие и съдържание", "Title and Content" }, { "Source Code Example", "Source Code Example" }, { "Image and Content", "Image and Content" }, { "Questions Slide", "Questions Slide" }, { "Blank Slide", "Blank Slide" }, { "Block scheme", "Blank Slide" }, { "About Slide", "About Slide" }, { "Last", "About Slide" }, { "Comparison Slide Dark", "Comparison Slide" }, { "", "" }, }; // Add layout names like "1_Section Title Slide", "2_Demo Slide" foreach (string layoutName in layoutMappings.Keys.ToArray()) { var mappedName = layoutMappings[layoutName]; for (int i = 1; i < 99; i++) { layoutMappings["" + i + "_" + layoutName] = mappedName; } } const string defaultLayoutName = "Title and Content"; var customLayoutsByName = new Dictionary <string, CustomLayout>(); foreach (CustomLayout layout in presentation.SlideMaster.CustomLayouts) { customLayoutsByName[layout.Name] = layout; } var layoutsForDeleting = new HashSet <string>(); // Replace the incorrect layouts with the correct ones for (int slideNum = 1; slideNum <= presentation.Slides.Count; slideNum++) { Slide slide = presentation.Slides[slideNum]; string oldLayoutName = slide.CustomLayout.Name; string newLayoutName = defaultLayoutName; if (layoutMappings.ContainsKey(oldLayoutName)) { newLayoutName = layoutMappings[oldLayoutName]; } if (newLayoutName != oldLayoutName) { Console.WriteLine($" Replacing invalid slide layout \"{oldLayoutName}\" on slide #{slideNum} with \"{newLayoutName}\""); // Replace the old layout with the new layout if (customLayoutsByName.ContainsKey(newLayoutName)) { slide.CustomLayout = customLayoutsByName[newLayoutName]; } else { slide.CustomLayout = customLayoutsByName[defaultLayoutName]; Console.WriteLine($" Cannot find layout [{newLayoutName}] --> using [{defaultLayoutName}] instead"); } layoutsForDeleting.Add(oldLayoutName); } } // Delete all old (and no longer used) layouts foreach (var layoutName in layoutsForDeleting) { Console.WriteLine($" Deleting unused layout \"{layoutName}\""); CustomLayout layout = customLayoutsByName[layoutName]; layout.Delete(); } }
static void FixInvalidSlideLayouts(Presentation presentation) { Console.WriteLine("Fixing the invalid slide layouts..."); var layoutMappings = new Dictionary <string, string> { { "Presentation Title Slide", "Presentation Title Slide" }, { "Presentation Title", "Presentation Title Slide" }, { "1_Presentation Title Slide", "1_Presentation Title Slide" }, { "Title Slide", "Title Slide" }, { "Title slide", "Title Slide" }, { "Section Title Slide", "Title Slide" }, { "Section Slide", "Title Slide" }, { "Заглавен слайд", "Title Slide" }, { "1_Title Slide", "Title Slide" }, { "2_Title Slide", "Title Slide" }, { "Title Only", "Title Slide" }, { "Section Header", "Title Slide" }, { "Picture with Caption", "Title Slide" }, { "Title and Content", "Title and Content" }, { "1_Title and Content", "Title and Content" }, { "2_Title and Content", "Title and Content" }, { "3_Title and Content", "Title and Content" }, { "4_Title and Content", "Title and Content" }, { "Заглавие и съдържание", "Title and Content" }, { "Title, Content", "Title and Content" }, { "Title, 2 Content", "Title and Content" }, { "Title and body", "Title and Content" }, { "Content with Caption", "Title and Content" }, { "Blank Slide", "Blank Slide" }, { "1_Blank Slide", "Blank Slide" }, { "Questions Slide", "Questions Slide" }, { "Слайд с въпроси", "Questions Slide" }, }; const string defaultLayoutName = "Title and Content"; var customLayoutsByName = new Dictionary <string, CustomLayout>(); foreach (CustomLayout layout in presentation.SlideMaster.CustomLayouts) { customLayoutsByName[layout.Name] = layout; } var layoutsForDeleting = new HashSet <string>(); // Replace the incorrect layouts with the correct ones for (int slideNum = 1; slideNum <= presentation.Slides.Count; slideNum++) { Slide slide = presentation.Slides[slideNum]; string oldLayoutName = slide.CustomLayout.Name; string newLayoutName = defaultLayoutName; if (layoutMappings.ContainsKey(oldLayoutName)) { newLayoutName = layoutMappings[oldLayoutName]; } if (newLayoutName != oldLayoutName) { Console.WriteLine($" Replacing invalid slide layout \"{oldLayoutName}\" on slide #{slideNum} with \"{newLayoutName}\""); // Replace the old layout with the new layout slide.CustomLayout = customLayoutsByName[newLayoutName]; layoutsForDeleting.Add(oldLayoutName); } } // Delete all old (and no longer used) layouts foreach (var layoutName in layoutsForDeleting) { Console.WriteLine($" Deleting unused layout \"{layoutName}\""); CustomLayout layout = customLayoutsByName[layoutName]; layout.Delete(); } }