Open XML SDK 2.0을 사용하는 작고 콘솔 프로그램이 있습니다. 기본적으로 PowerPoint 슬라이드에서 모든 그림을 가져오고 싶습니다. 나는이 프로그램을 실행하면,하지만, 나는 다음과 같은 오류가 발생합니다 :PowerPoint 2010 슬라이드의 모든 그림을 가져오고 있지만 오류가 발생했습니다.
Cannot access part because parent package was closed.
내 PPT는 하나 개의 이미지와 하나 개의 슬라이드가 있습니다. 이것은 단지 프로토 타입 프로그램입니다. Open XML SDK 2.0에 익숙하지 않아서이 오류가 무엇을 말하고 있는지, 어떻게 고쳐야하는지 잘 모르겠습니다. 나는 누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다. GetSlidePart
에서
using System;
using System.Collections.Generic;
using DocumentFormat.OpenXml.Presentation;
using A = DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using System.Text;
using System.Data;
using System.Linq;
namespace OpenXmlDemo
{
public class Program
{
static void Main(string[] args)
{
var file = @"C:\Users\kjennings\Desktop\Test PPTs\This is the Title - Copy.pptx";
var index = 0;
var slidePart = GetSlidePart(file, index);
var images = slidePart.Slide.Descendants<Picture>().Select(p => p); // error occurs here
foreach (var image in images)
{
// Just placeholder code below. It never makes it here.
var pic = image;
}
}
public static SlidePart GetSlidePart(string docName, int slideIndex)
{
using (var ppt = PresentationDocument.Open(docName, false))
{
// Get the relationship ID of the first slide.
var presentationPart = ppt.PresentationPart;
// Verify that the presenation part and the presenation exist,
if (presentationPart != null && presentationPart.Presentation != null)
{
var presentation = presentationPart.Presentation;
if (presentation.SlideIdList != null)
{
var slideIds = presentation.SlideIdList.ChildElements;
if (slideIndex < slideIds.Count)
{
// Get the relationship ID of the slide.
var slidePartRelationship = (slideIds[slideIndex] as SlideId).RelationshipId;
// Get the specified slide part from the relationship ID.
var slidePart = (SlidePart)presentationPart.GetPartById(slidePartRelationship);
return slidePart;
}
}
}
// No slide found.
return null;
}
}
}
}
이 매우 도움이 답변을 주셔서 너무 감사합니다! – Kevin
@kevin을 도와 드리겠습니다. – petelids