Closed jozefizso closed 4 years ago
I'm reposting the issue here as my original comment was deleted:
Hi Siam1205, this repository (https://github.com/netoffice/NetOffice) is not maintained anymore. The NetOffice project was moved to https://github.com/NetOfficeFw/NetOffice
If you are using NuGet packages, please update the to use the NetOfficeFw.Word (not the Fw in the package name) > which are our official NetOffice releases.
Regards, Jozef
Thank you for posting my Issue here. I did not notice the repository has moved.
Do you have sample code?
I'm not familiar with how the InsertFile
method works and when I tried to write a sample, I ended up with document like this:
Code:
doc.Content.InsertFile(@"code.html");
@Siam1205
I tried it with this code (full Gist https://gist.github.com/jozefizso/12df9dd27dab16b76440ee95f1b21463):
doc.Content.InsertFile(@"code.html");
<html>
<body>
<h4 itemprop="content rn_title">H4 Title</h4>
<div itemprop="content">
<p>Sample content....</p>
<div class="infomalfigure">
<div class="mediaobject">
<p>Image...</p>
<p><img src="NetOfficeLogo_200x200.png"></p>
</div>
</div>
</div>
</body>
</html>
When using relative path, the image file must be next to the DOCX document. It also worked with absolute paths. I did not try if it is possible to embed the image into the Word document.
This is Word 365 Version 2006.
Thank you for your help.
With what you posted here, you got me on something. In fact, the tool that uses the API really acts a bit strange. I digged deeper into it (I didn't develop it myself) and found what it does:
It creates a temporary HTML file somewhere under C:\<User>\Temp
which references an image like this:
<p><img src="path\to\img.png" alt="" height="110" width="223"></p>
. However, the referenced image is not available at this point. It's just the HTML document.
When the Word document is being created, the referenced image becomes available. This is because the created Word document resides at a different location than the source HTML document. To be more concrete, The Word document is writen to RootDirectory
whereas the image is located at RootDirectory\path\to\img.png.
With Word 2013: I guess that, with Word 2013, the image is being embedded no matter whether the image, referenced in the HTML code, is available or not.
With Word 365: When the Word document is being created , the referenced image cannot be found. I guess this results in the "dead" reference not being piped to the Word document properly.
Does this make sense to you?
I want to add the fact that when the image reference is valid hence when the image is available under the referenced location, it does work as you have shown. Just when the referenced image is not available during the invocation of InserFile(htmlFile)
, the Word document is broken. However, this worked with Word 2013.
Yes, that could be behavior which changed between Word 2013 and 365. NetOffice just calls their implementation, so it depends on how Word behaved internally.
OK, thank you again. For me, the issue can be considered as resolved.
@Siam1205 you are welcome.
BTW: May I ask you if you have also received e-mail like the one mentioned in this comment? https://github.com/fslaborg/Deedle/pull/505#issuecomment-659310988
@jozefizso No, i did not receive such e-mails.
Original issue: https://github.com/netoffice/NetOffice/issues/12
I have used the C# API for a long time with Word 365 installed on my system. I use it inside a small tool to create Word files based on HTML files but once I updated to Word 365, the tool failed to insert images properly. Everything else seems to work well.
As an example, the Range.InsertFile (range.InsertFile(tmpHtmlFile.File);) does not insert the image to the Word document, when called with an HTML file storing the following content (I used an image to omit markdown):
Will this be supported in future since I rely on this tool?