gpt4 book ai didi

c# - 使用 Open XML SDK 排序和删除幻灯片

转载 作者:行者123 更新时间:2023-11-30 16:21:16 26 4
gpt4 key购买 nike

我正在处理这个例程,我需要以编程方式删除“隐藏”的 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 属性吗?请参阅我在代码中的评论。谢谢你!里肖。

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;
}
}
}

}
}

最佳答案

发布此内容后一分钟,我意识到要获取特定的幻灯片,我需要执行以下操作:SlidePart slidePart = presentationPart.GetPartById(slideRelId) as SlidePart; 就在 foreach 循环之前。

关于c# - 使用 Open XML SDK 排序和删除幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13384003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com