Reputation: 11
I want to transfer the word image with the following code, but I think because the image is loaded late, I get an error:
System.Runtime.InteropServices.COMException
Where is my mistake?
// Word uygulamasını oluşturuyoruz.
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
// Yeni doküman oluşturuyoruz.
WordApp.Documents.Add();
// word açılıyor.
WordApp.Visible = true;
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
var link = "https://zeminprogram-debb.restdb.io/media/uydu.png";
doc.InlineShapes.AddPicture(link, Type.Missing, Type.Missing, Type.Missing);
Upvotes: 0
Views: 443
Reputation: 11
unfortunately, again the same problem,
no problem retrieving from folder but still giving the same error when retrieving from url
var myImageFullPath = "https://zeminprogram-debb.restdb.io/media/uydu.png";
using (DocX document = DocX.Create(@Application.StartupPath + "\\dene.doc"))
{
// Add an image into the document.
Xceed.Document.NET.Image image = document.AddImage(myImageFullPath);
// Create a picture (A custom view of an Image).
Picture picture = image.CreatePicture();
// Insert a new Paragraph into the document.
// Insert a new Paragraph into the document.
Paragraph p1 = document.InsertParagraph();
// Append content to the Paragraph
p1.AppendLine("LOGO").AppendPicture(picture).Append(" its funky don't you think?");
p1.AppendLine();
p1.AppendPicture(picture);
document.Save();
// Save this document.
}
Upvotes: 0
Reputation: 753
You can achieve this functionality by using DocX library
and here is the sample code :
var myImageFullPath = "C:\tmp\sample.png";
using (DocX document = DocX.Create(@"docs\HelloWorldAddPictureToWord.docx"))
{
// Add an image into the document.
Image image = document.AddImage(myImageFullPath);
// Create a picture (A custom view of an Image).
Picture picture = image.CreatePicture();
// Insert a new Paragraph into the document.
Paragraph title = document.InsertParagraph().Append("This is a test for a
picture").FontSize(20).Font(new FontFamily("Comic Sans MS"));
title.Alignment = Alignment.center;
// Insert a new Paragraph into the document.
Paragraph p1 = document.InsertParagraph();
// Append content to the Paragraph
p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky
don't you think?");
p1.AppendLine();
p1.AppendPicture(picture);
// Save this document.
document.Save();
}
Upvotes: 1