DocumentFormat.OpenXml Hinzufügen von ein Bild in ein word-doc

Erstelle ich ein einfaches word-doc, mit dem openXml SDK.
Es funktioniert so weit.
Nun, wie kann ich ein Bild aus meiner Datei-system zu diesem doc? Mir egal wo es ist in den doc-nur damit es da ist.
Danke!
Hier ist was ich habe, so weit.

 string fileName = "proposal"+dealerId +Guid.NewGuid().ToString()+".doc";
       string filePath = @"C:\DWSApplicationFiles\Word\" + fileName;
       using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document, true))
       {
           MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();

           mainPart.Document = new Document();
           //create the body
           Body body = new Body();
           DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
           DocumentFormat.OpenXml.Wordprocessing.Run runParagraph = new DocumentFormat.OpenXml.Wordprocessing.Run();         

           DocumentFormat.OpenXml.Wordprocessing.Text text_paragraph = new DocumentFormat.OpenXml.Wordprocessing.Text("This is a test");
           runParagraph.Append(text_paragraph);
           p.Append(runParagraph);
           body.Append(p);
           mainPart.Document.Append(body);
           mainPart.Document.Save();              
       }

InformationsquelleAutor twaldron | 2011-05-13

Schreibe einen Kommentar