2017-05-02 2 views

答えて

1

もちろん、画像のbase64を取得することができます。これは、必要な処理です。 これはちょうど)だけcontext.document.getSelection(でそれを行う選択のための画像のコレクションにアクセスしている。inlinePictures.getFirst()

async function getImage() { 
 
    try { 
 
     Word.run(async (context) => { 
 
      const firstPicture = context.document.body.inlinePictures.getFirst(); 
 
      context.load(firstPicture); 
 
      await context.sync(); 
 

 
      const base64 = firstPicture.getBase64ImageSrc(); 
 
      await context.sync(); 
 

 
      console.log(base64.value); 
 
     }) 
 
    } 
 
    catch (exception) { 
 
     OfficeHelpers.Utilities.log(exception); 
 
    } 
 
}

0

Word APIgetBase64ImageSrcメソッドを使用して、Base64エンコードバージョンのイメージを取得できます。

Word.run(function (context) { 
    var base64Image; 

    var range = context.document.getSelection(); // Get selection 
    var images = range.inlinePictures; // Get images from selection 
    context.load(images); // Load images from document 
    return context.sync() 
     .then(function() { 
      // Make sure we have at least 1 image 
      if (images.items.length > 0) 
       // grab the base64 encoded image 
       image = images.getFirst().getBase64ImageSrc(); 
      else 
       console.log("No images selected"); 
     }) 
     .then(context.sync) 
     .then(function() { 
      // image.value now contains the base64 encoded image 
      console.log(image.value); 
     }) 
     .then(context.sync); 
}) 
+0

おかげでマルクを..... – Leo

関連する問題