none
C#으로 PowerPoint 파일을 읽을때 Exception RRS feed

  • 질문

  • Visual Studio로 PowerPoint 의 Table를 읽어 들이려고 합니다만

    '요청한 도형은 선택할 수 없도록 잠겨 있습니다.'

    이란 Exception이

    foreach (PowerPoint.Shape shape in slide.Shapes) 의 in을 실행하면서 나는데 왜 그런지 모르겠습니다.

    혹시 아시는 분 계실까요? ErrorCode는 -2147352567 으로 나타나네요.

    코드는 아래와 같습니다.

    private static void PowerPointTest()
            {
                string FilePath = @"test.pptx";
                string NewFolderPath = @"D:\ppt";
                PowerPoint.Application App = new PowerPoint.Application();

                PowerPoint.Presentation presentation = App.Presentations.Open(FilePath, OfficeCore.MsoTriState.msoTrue, OfficeCore.MsoTriState.msoFalse, OfficeCore.MsoTriState.msoFalse);
                Trace.WriteLine("Slide Count: " + presentation.Slides.Count);

                try
                {
                    int slideIndex = 0;
                    foreach (PowerPoint.Slide slide in presentation.Slides)
                    {
                        Trace.WriteLine("Current Slide: " + slideIndex++);
                        Trace.WriteLine("Shape Count: " + slide.Shapes.Count);

                        int i = 0;
                        foreach (PowerPoint.Shape shape in slide.Shapes)   // in에서 에러 발생
                        {
                            if (shape.HasTable == OfficeCore.MsoTriState.msoTrue)
                            {
                                foreach (PowerPoint.Row row in shape.Table.Rows)
                                {

                                     ....

                                }
                            }
                        }
                    }

                    //presentation.SaveAs(NewFolderPath, PowerPoint.PpSaveAsFileType.ppSaveAsJPG, OfficeCore.MsoTriState.msoFalse);
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                }
                finally
                {
                    presentation.Close();
                }
            }

    2017년 5월 24일 수요일 오전 10:04

답변