В программе, пользователь выбирает файлы, которые можно вложить в docx файл. Добавление картинок я сделал. Как добавлять xlsx и pdf(желательно).
Используемая библиотека: DocumentFormat.OpenXml.
Так я добавляю в документ картинки:
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());
}
Есть такой пример: https://code.msdn.microsoft.com/office/How-to-embed-Excel-sheet-e4c252b5. Но там в docx добавляется картинка при клике на которую открывается xlsx документ. А мне нужно чтобы содержимое этого документа(xlsx) вставилось в docx.
Жду любые предложения.
EmbedExcelIntoWordDoc.Properties.Resource1.BASE64_STRING_EXCEL_ICON
пишет does not exists in the current context. Я не знаю что подключить нужно.