0

I am creating an Office 2013 app, using HTML & Javascript. I want to include one feature in the app, i.e., when the User clicks a certain button, the corresponding image gets inserted in the document. I tried this method..

HTML:

<button id="img-insert-btn">Insert Image</button>

jQuery:

$('#img-insert-btn').click(insertImage);

Javascript:

function insertImage() {
Office.context.document.setSelectedDataAsync("../ImageFolder/Image.png");
}

The method I wrote above, inserts that file path into the document, instead of inserting the image. Please help. P.S. jQuery can also be implied.

2 Answers 2

1

Do this like that:

$(document).ready(function(){
    $('button').click(function(){
        $('body').append('<img src="http://www.gratuit-en-ligne.com/telecharger-gratuit-en-ligne/telecharger-image-wallpaper-gratuit/image-wallpaper-animaux/img/images/image-wallpaper-animaux-autruche.jpg">');
    });
})

Fiddle demo.

Sign up to request clarification or add additional context in comments.

2 Comments

Nothing bro! its not working... the image you are inserting works for webpages... Office Apps are different from webpages.. I want to insert the image inside the Word document, on which user is working.. not in the body of the HTML document!
0

Javascript:

var imgHTML = "<img " +
"src='http://i.msdn.microsoft.com/fp123580.AppHome2(en-us,MSDN.10).png'"
+ " alt ='apps for Office image' img/>";

function setHTMLImage(imgHTML)
    {
        Office.context.document.setSelectedDataAsync(
            imgHTML, { coercionType: "html" },
            function (asyncResult) {
                if (asyncResult.status == "failed") {
                    write('Error: ' + asyncResult.error.message);
                }
            });
    }

Answer found here by @guli

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.