2011-10-02 17 views
2

イメージファイル名をpptxファイルのイメージから取得する必要があります。私はすでに、画像からのストリームを得ましたが、私は、画像ファイルの名前を得ませんでした...ここに私のコードは次のとおりです。パワーポイントファイルからイメージ名を取得する

private static Stream GetParagraphImage(DocumentFormat.OpenXml.Presentation.Picture  picture, DocumentFormat.OpenXml.Packaging.PresentationDocument presentation, ref  MyProject.Import.Office.PowerPoint.Presentation.Paragraph paragraph) 
{ 
     // Getting the image id 
     var imageId = picture.BlipFill.Blip.Embed.Value; 
     // Getting the stream of the image 
     var part = apresentacao.PresentationPart.GetPartById(idImagem); 
     var stream = part.GetStream(); 
     // Getting the image name 
     var imageName = GetImageName(imageId, presentation); 
/* Here i need a method that returns the image file name based on the id of the image and the presentation object.*/ 
     // Setting my custom object ImageName property 
     paragraph.ImageName = imageName; 
     // Returning the stream 
     return stream; 
} 

誰でも私はこれを達成することができます方法を知っていますか? ありがとうございます!

答えて

0

PPTXファイル内の画像/映像のための2人のファイル名、実際にあります。それはあなたが次の関数を使用することができます PPTXファイルに埋め込まれているとして、あなたがイメージのファイル名が必要な場合は

は:

public static string GetEmbeddedFileName(ImagePart part) 
{ 
    return part.Uri.ToString(); 
} 

あなたのイメージのorignialファイルシステム名が必要な場合は、次の関数を使用することができます:BE

public static string GetOriginalFileSystemName(DocumentFormat.OpenXml.Presentation.Picture pic) 
{ 
    return pic.NonVisualPictureProperties.NonVisualDrawingProperties.Description; 
} 

をGINのEDIT:

using (var doc = PresentationDocument.Open(fileName, false)) 
{ 
    var presentation = doc.PresentationPart.Presentation; 

    foreach (SlideId slide_id in presentation.SlideIdList) 
    { 
    SlidePart slide_part = doc.PresentationPart.GetPartById(slide_id.RelationshipId) as SlidePart; 
    if (slide_part == null || slide_part.Slide == null) 
     continue; 
    Slide slide = slide_part.Slide; 

    foreach (var pic in slide.Descendants<DocumentFormat.OpenXml.Presentation.Picture>()) 
    { 
     string id = pic.NonVisualPictureProperties.NonVisualDrawingProperties.Id; 
     string desc = pic.NonVisualPictureProperties.NonVisualDrawingProperties.Description; 

     Console.Out.WriteLine(desc); 
    } 
    } 
} 

のEND EDIT

希望、このことができます:

ここでは、完全なコード例です。

+0

Hii、答えがありますが、NonVisualDrawingPropertiesプロパティがPictureオブジェクトに直接存在しません。まず、NonVisualDrawingProperties.DescriptionのNonVisualPicturePropertiesを取得する必要がありますが、このプロパティをacessにするとnullを返します。私は以前に入力する必要がある何かを使用していますか? –

+0

@ mnatan.brito:そうです。 NonVisualDrawingPropertiesプロパティはピクチャクラスには直接存在しません。より完全なコードサンプルで私の答えを更新しました。私はパワーポイントの2007年の文書を再び走らせて、元のファイル名を印刷します。お役に立てれば。 – Hans

+0

descriptionプロパティは、pptx内のすべてのイメージに対してnullを返しています。 –

関連する問題