In the program, the user selects files that can be attached to the docx file. I added the pictures. How to add xlsx and pdf (desirable).

Library used: DocumentFormat.OpenXml.

So I add images to the document:

public static void InsertAPicture(WordprocessingDocument wordprocessingDocument, MainDocumentPart mainPart, string fileName) { ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); System.Drawing.Image img = System.Drawing.Image.FromFile(fileName); var width = img.Width; var height = img.Height; img.Dispose(); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AppenderToDoc.AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart), width, height); mainPart.Document.Body.AppendChild(new Paragraph()); } 

There is an example: https://code.msdn.microsoft.com/office/How-to-embed-Excel-sheet-e4c252b5 . But there the docx image is added when you click on which opens the xlsx document. And I need the contents of this document (xlsx) to be inserted into the docx.

Waiting for any suggestions.

  • look at this guide code.msdn.microsoft.com/office/… - RusArt
  • just now I look at it while I understand. - endovitskiiy
  • the point is that an OLE object is inserted - RusArt
  • I have in this place: EmbedExcelIntoWordDoc.Properties.Resource1.BASE64_STRING_EXCEL_ICON writes I do not know what to connect. - endovitskiiy
  • there you can download an example, download and see that this is a resource that was added to the project. - RusArt

0