NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

No support for Word 365 #274

Closed jozefizso closed 4 years ago

jozefizso commented 4 years ago

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):

image

Will this be supported in future since I rely on this tool?

jozefizso commented 4 years ago

I'm reposting the issue here as my original comment was deleted:

netoffice_issue_12_01

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

Siam1205 commented 4 years ago

Thank you for posting my Issue here. I did not notice the repository has moved.

jozefizso commented 4 years ago

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: image

Code:

doc.Content.InsertFile(@"code.html");
jozefizso commented 4 years ago

@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.

image

This is Word 365 Version 2006.

Siam1205 commented 4 years ago

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?

Siam1205 commented 4 years ago

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.

jozefizso commented 4 years ago

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.

Siam1205 commented 4 years ago

OK, thank you again. For me, the issue can be considered as resolved.

jozefizso commented 4 years ago

@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

Siam1205 commented 4 years ago

@jozefizso No, i did not receive such e-mails.