excel中插入图片

阅读次数 3

1、通过 app.Range0.Top 获取的单元格顶边距,在sheet未置顶时,无法准确的获取到单元格到顶部的绝对距离,如何在sheet滑动到任意位置时,获取正确的单元格到顶部的绝对距离。 2、插入图片 AddPicture 接口,可否插入到单元格中,而不是通过 left、top绝对位置定位?

2 Answers

现在用绝对位置来定位插入图片的位置会出现一个问题,当文档加载完成时,如果文档向顶部自动缩进了几行,那么按照绝对定位来插入图片就会出现定位错误。这是正常情况:正常情况如果是这样缩进了5行,那么应该签到校核的签名图片就会签到其上方的椭圆形处:

您好,问题1获取单元格到顶部距离需要确保当前单元格在可视区内,设计如此,建议您能正常在文档看到该单元格后再调用api获取位置 问题2 可以试试这个方法

await instance.ready()

 const app = instance.Application

 // 区域对象
 const range = await app.Range('E1')
  // 向目标单元格插入图片
 range.InsertImage(
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACH1BMVEUAAAA9kP8mpv9Fv/8QT94TXeQAfv8trP0xr/0VUdoAcv8LgPs1sf4AgP4QUuURTuEVl/ksq/wAg/84tf4NUt80sf0bnPsPUuAAYfsAgP4UTtYAY/8GXPQRkv1Jxv8AZP86tv9Bvv9Gv/9Atv8KiPUOVesAZ+wbS8wUl/kjo/sAYv8PVekjovxBu/8AY/8trPxCu/8AW/AAcvAxsP0npvsYTdElo/oQT9o+uP8AYv8KVOIHdugAYfwAfPwbfe49uf4XmfkcdOopo/oAYv86tf4AYf8TT9cZaeYVTdUJVOUcnvsAYv8Agv9Iwv8AYv9Jwf8bSs0gofoAY/8Ag/9Gv/8en/oAYf9Fv/8AWuQZS80AdO5BvP8AYv9DvP8Umfo9uv8LVOUAgf8amfk/uf8AY/8Ag/8Ahf8TUdgVT9UNWOknov8trPwxr/wmpvspqfs1sv0io/s5tf0AgP8bnfoMV+4AYPoAYv8AYf4AYfwAe/sen/oAd/gAXvYAff0LW/MLWfEOUN0PT9oSTtZAu/49uP0qqfweoPoXmvkAdPUAXPIAcf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