Office.js加载项:在Excel 2016中插入图像/图片 [英] Office.js Add-in: Insert image/picture in Excel 2016

查看:464
本文介绍了Office.js加载项:在Excel 2016中插入图像/图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用新的Office.js API将简单图像添加到excel电子表格中的特定位置?

How do you add a simple image to a specific location on an excel spreadsheet using the new Office.js api?

推荐答案

此答案说明了如何在Word中执行此操作: https://stackoverflow.com/a/38194807/3806701 ,同样,我也可以通过Excel来做到这一点:

This answer explains how to do this in Word: https://stackoverflow.com/a/38194807/3806701, and similarly, I was able to do it this way Excel:

insertImageBase64New() {
  Excel.run(async (ctx) => {

    let sheet = ctx.workbook.worksheets.getItem("Sheet1");
    let address = "C3";
    let range = sheet.getRange(address);
    range.select();
    await ctx.sync();

    Office.context.document.setSelectedDataAsync(this.getBase64(), {
      coercionType: Office.CoercionType.Image,
      imageLeft: 0,
      imageTop: 0,
      imageWidth: 300,
      imageHeight: 100
    }, function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
          console.log("Action failed with error: " + asyncResult.error.message);
        }
    });
  });
}

getBase64() {
    return "return "iVBORw0KGgoAAAANSUhEU..."; //put your base64 encoded image here
}

文档参考: https://dev.office.com/reference/加载项/excel/rangefill

我曾经对图像进行编码的随机网站: https://www.browserling. com/tools/image-to-base64

Random website I used to encode an image: https://www.browserling.com/tools/image-to-base64

这篇关于Office.js加载项:在Excel 2016中插入图像/图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆