2010-03-01 3 views
3

텍스트와 이미지를 PowerPoint에서 Word로 복사하려면 응용 프로그램이 필요합니다. 이 라이브러리를 사용합니다 : Microsoft.Office.Interop.PowerPoint 및 Microsoft.Office.Interop.Word. C# 이미지 형식 복사 PowerPoint to Word

는 텍스트들로 전송하기 쉬운,하지만 난 파워 포인트에 불과 이미지를 포함하는 형태를 발견 할 때, 그것은이 오류를 보여줍니다 " 일반 오류가 발생했습니다 GDI +", 코드의이 부분에서 :

foreach (PowerPoint.Shape shape in slide.Shapes) 
{ 
    if (shape.HasTextFrame != MsoTriState.msoTrue){ 
     shape.Copy(); 
     Image img = (Image)Clipboard.GetData(DataFormats.Bitmap); 
     string filepath = Environment.SpecialFolder.Desktop + "\\img.jpg"; 
     if (File.Exists(filepath)) 
     { 
     File.Delete(filepath); 
     } 
     img.Save(filepath); 
     doc.Shapes.AddPicture(filepath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); 
    } 
} 

이 상황에서 PowerPoint에서 Word로 이미지가 포함 된 도형을 복사하려면 어떻게해야합니까? 도움이됩니다. 나는 약간의 코드 샘플을 선호한다.

감사합니다.

+0

shape.Copy() 또는 Clipboard.GetData (..)가 실패합니까? –

+0

Clipboard.GetData (..)에서 실패합니다 – Emanuel

+0

코드는 Win7 상자 (.Net4 및 Office 2010)에서 제대로 작동합니다. 어떤 OS를 실행하고 어떤 버전의 .Net? –

답변

0

이렇게 코드를 다시 작성하면 작동합니까? GetImage는 자동 변환을 수행하여 이미지인지 확인합니다. 비트 맵인 경우 클립 보드에 실제로 이미지가 포함되도록 코드에 포함 된 체크를 포함 할 수 있습니다.

shape.Copy(); 
bool imgOk = Clipboard.ContainsImage(); 
if (imgOk) 
{ 
    Image img = Clipboard.GetImage(); 
    MessageBox.Show(imgOk.ToString()); 
    string filepath = @"c:\temp\img.jpg"; 
    if (File.Exists(filepath)) 
    { 
     File.Delete(filepath); 
    } 
    img.Save(filepath); 
} 
관련 문제