none
display image in word RRS feed

  • Question

  • I'm exporting an html fil with an image to word. How d I display the image in word? It's a red X... Arg!
    • Moved by 许阳(无锡)Moderator Monday, April 25, 2011 8:15 AM Off-topic (From:Word for Developers)
    • Moved by Tagore Bandlamudi Tuesday, April 26, 2011 9:31 AM As per request (From:Off-Topic Posts (Do Not Post Here))
    Wednesday, April 20, 2011 9:48 PM

Answers

  • The images are saved to a folder in my web app. How do you set what the path to the images for MSWord 2007?


    Hi n3wb13

    It appears things have been glued back together again :-)

    This is going to depend on exactly what you need to do with this HTML file, once it's been opened in Word.

    The approach I was thinking about, when I replied last, was to copy the images to a local folder, change the link in the HTML file to that folder, then open the document.

    There are possibilities, once the file is open in Word, to insert the images via the Interop. But I'm not sure that's an acceptable approach when using a web app?

    Another possibility would be to "transform" the HTML content into Word's OpenXML file format (a docx) before saving the file to the user's folder. This would allow you to embed the image into the document, as part of the OpenXML "package". If you're interested in that approach, I recommend the resources at OpenXMLDeveloper.org and you'd need to follow up in the Open XML SDK forum.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by n3wb13 Friday, April 29, 2011 8:24 PM
    • Unmarked as answer by n3wb13 Friday, April 29, 2011 9:27 PM
    • Marked as answer by Cindy Meister MVPModerator Sunday, May 1, 2011 8:20 AM
    Tuesday, April 26, 2011 5:18 PM
    Moderator

All replies

  • Hi n3wb13,

     

    Thanks for posting in the MSDN Forum.

     

    Would you clarify the relationship between your issue and Word development? It more like an end-user issue.

     

    This is the forum for Word developers. You will receive better support if you post it in the http://answers.microsoft.com/en-us/office/forum/word .

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 21, 2011 2:13 AM
    Moderator
  • It's a web app converting an html file to a word document. The problem is the images in the html file isn't being displayed in the word document.
    Thursday, April 21, 2011 2:31 AM
  • Hi n3wb13,

     

    As far as I know, VSTO doesn’t support such issue. Please take a look at http://support.microsoft.com/kb/257757 .

     

    If I have misunderstood anything, please feel free to let me know.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 22, 2011 1:41 AM
    Moderator
  • Hi n3wb13

    I don't know what Tom's thinking... This is the Word Developer forum and a web app has nothing to do with VSTO. Your question is in the right place...

    Could you provide more details about how your app is working? Is it, for example, saving the HTML file to disk then opening it in Word?

    Which versin of Word are we dealing with?

    Most HTML files don't "contain" images, the images are linked. If that's the case it's possible that Word isn't able to locate the images for display.


    Cindy Meister, VSTO/Word MVP
    Friday, April 22, 2011 7:13 AM
    Moderator
  • Yes, it's an html file saved to disk. I'm opening the html file in MS Word 2007. The images aren't displaying. The error is the image has been moved, renaed, or deleted.

    Friday, April 22, 2011 1:45 PM
  • Yes, it's an html file saved to disk. I'm opening the html file in MS Word 2007. The images aren't displaying. The error is the image has been moved, renaed, or deleted.


    Yes, and: if you look at the actual HTML mark-up in the file, where should the image come from? Is it a link Word can actual access?

    It's important to realize that Word is a word-processing software, not a browser (or a page layout program, or... so many other things people would like it to be). So it's going to behave like a word-processor, designed to function on an end-user desktop. Word has trouble accessing things that aren't local or in a LAN network. Quite likely, it simply can't parse this link to bring the image in.


    Cindy Meister, VSTO/Word MVP
    Saturday, April 23, 2011 6:03 AM
    Moderator
  • The image source is a link accessible on the internet. I don't whether or not it's assessible by word. I'm new to programming against office products. How do you know whether or not an image is assessible by word?


    Saturday, April 23, 2011 11:38 PM
  • The image source is a link accessible on the internet. I don't whether or not it's assessible by word. I'm new to programming against office products. How do you know whether or not an image is assessible by word?



    Simplest is to try to insert that picture via the link path as a Word end-user. That would be Insert/Picture, then navigate to the path using the address bar across the top. If you can't get there, then Word can't get there to pick up the picture for the document :-)

    Does your web app have full access to the folder where the linked picture is? Could it copy the picture to the local machine, along with the html file, and alter the link?


    Cindy Meister, VSTO/Word MVP
    Sunday, April 24, 2011 5:41 AM
    Moderator
  • Thank you. I'm working on grabbing the image source from the url source code and saving it to a folder. Stay tuned :)
    Sunday, April 24, 2011 9:59 PM
  • The images are saved to a folder in my web app. How do you set what the path to the images for MSWord 2007?
    Monday, April 25, 2011 4:02 PM
  • Somebody keeps moving my threads to the wrong forum. Original post http://social.msdn.microsoft.com/Forums/en-US/Offtopic/thread/5ea19216-05d1-4b21-8f94-d78bf4c32ad0.
    I'm exporting an html file with images to word but the imaes aren't displayed in the word document. The images are saved to a folder in my web app when the html file is converted to a word document. The error in MS Word is that it can't find the image files. How do I set the path to display the images in word?
    Monday, April 25, 2011 4:35 PM
  • Hi n3wb13

    Thanks for giving us a heads-up. I unfortunately don't have moderator permissions sufficient enough to move that thread back here, where it definitely does belong! I've contacted someone who should be able to arrange it and hope things are soon in order again. If that person is successful, this thread might then be deleted - please don't be shocked if that turns out to be the case :-)!


    Cindy Meister, VSTO/Word MVP
    Monday, April 25, 2011 5:28 PM
    Moderator
  • Thank you Cindy :)
    Monday, April 25, 2011 5:52 PM
  • The images are saved to a folder in my web app. How do you set what the path to the images for MSWord 2007?


    Hi n3wb13

    It appears things have been glued back together again :-)

    This is going to depend on exactly what you need to do with this HTML file, once it's been opened in Word.

    The approach I was thinking about, when I replied last, was to copy the images to a local folder, change the link in the HTML file to that folder, then open the document.

    There are possibilities, once the file is open in Word, to insert the images via the Interop. But I'm not sure that's an acceptable approach when using a web app?

    Another possibility would be to "transform" the HTML content into Word's OpenXML file format (a docx) before saving the file to the user's folder. This would allow you to embed the image into the document, as part of the OpenXML "package". If you're interested in that approach, I recommend the resources at OpenXMLDeveloper.org and you'd need to follow up in the Open XML SDK forum.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by n3wb13 Friday, April 29, 2011 8:24 PM
    • Unmarked as answer by n3wb13 Friday, April 29, 2011 9:27 PM
    • Marked as answer by Cindy Meister MVPModerator Sunday, May 1, 2011 8:20 AM
    Tuesday, April 26, 2011 5:18 PM
    Moderator
  • I copied the images to a folder. I'm using regex to replace the tag. When stepping through code the path variable, replacment, include the C drive. The image tag's src attribute doesn't in the sourceCode variable. I think that's why the image isn't displaying. I don't want to hard code the beginning of the img src because I don't know where it will be installed.

    string regexExpression = "(<)" + "((?:[a-z][a-z]+))" + "(\\s+)" + "((?:[a-z][a-z]+))" + "(=)" + "(\".*?\")" + "(\\/)" + "(>)";
    string replacment = "<img src=\"" + HttpContext.Current.Server.MapPath("~/folder/doc/image1.jpg") + "/>";
    sourceCode = sourceCode.Replace(regexExpression, replacment);


    Friday, April 29, 2011 9:55 PM
  • Hi n3wb13

    <<The image tag's src attribute doesn't in the sourceCode variable. I think that's why the image isn't displaying. I don't want to hard code the beginning of the img src because I don't know where it will be installed.>>

    Your first statement above is incomplete, so I'm not sure what "doesn't in the source code". However, when it comes to the actual code in the HTML document you do need to ask somewhere else. We can only help you with the Word side of things, not with the HTML you're importing.


    Cindy Meister, VSTO/Word MVP
    Saturday, April 30, 2011 6:24 AM
    Moderator
  • I'm sorry for the grammar error. I meant to say, "The image tag's src attribute isn't in the sourceCode variable." I'll try another forum. Thank you for all your help.
    Saturday, April 30, 2011 1:26 PM