【发布时间】:2012-11-15 01:43:32
【问题描述】:
我正在处理这个例程,我需要以编程方式删除“隐藏”的 PowerPoint 幻灯片。我对 Open XML 不太了解,我修改了一段代码,该代码最初删除了一张幻灯片,其中该方法将幻灯片索引作为参数,如本文所述 How to: Delete a slide from a presentation (Open XML SDK) 文章中所述。
但是我了解到,通过 SlideParts 集合的迭代默认情况下会按照幻灯片的最后编辑顺序而不是按照它们在演示文稿中出现的顺序对幻灯片进行排序。为此,必须按照 Iterating of SlideParts with the OpenXml SDK 文章中的建议遍历 SlideIdList。
在包含遍历 SlideList 的 foreach 循环的代码中,我需要获取幻灯片的 Show 属性以获取隐藏幻灯片的索引。
如果我在循环中使用 SlideIdList,是否有人知道如何获取 Show 属性?在代码中查看我的 cmets。谢谢!理庄。
public static void DeleteSlide(string presentationFile)
{
using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, true))
{
// Get the presentation part from the presentation document.
PresentationPart presentationPart = presentationDocument.PresentationPart;
// Get the presentation from the presentation part.
Presentation presentation = presentationPart.Presentation;
// Get the list of slide IDs in the presentation.
SlideIdList slideIdList = presentation.SlideIdList;
int slideIdx = -1;
foreach (SlideId _slideId in presentation.SlideIdList)
{
slideIdx++;
string relId = _slideId.RelationshipId.Value;
>>>>> // Here is where I need to checkf for Slide.Show.HasValue as
// as the code suggests but this property belongs to a
// presentationDocument.PresentationPart.SlideParts object as in
// foreach(Slide slide in presentationDocument.PresentationPart.SlideParts.
if (slide.Slide.Show != null)
{
if (slide.Slide.Show.HasValue != null)
{
// Pass the presentation to the next CountSlide method
// and return the slide count.
//return CountSlides(presentationDocument);
// Get the slide ID of the specified slide
SlideId slideId = slideIdList.ChildElements[slideIdx] as SlideId;
// Get the relationship ID of the slide.
string slideRelId = slideId.RelationshipId;
// Remove the slide from the slide list.
slideIdList.RemoveChild(slideId);
// Removed code that looks for a custom presentation
// Save the modified presentation.
presentation.Save();
// Get the slide part for the specified slide.
SlidePart slidePart = presentationPart.GetPartById(slideRelId) as SlidePart;
// Remove the slide part.
presentationPart.DeletePart(slidePart);
break;
}
}
}
}
}
【问题讨论】:
标签: c# openxml openxml-sdk