You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ExcelJS中删除/过滤含图片行时图片残留问题求助

ExcelJS删除/过滤行时图片残留问题求助

在ExcelJS v4.4.0/v4.3.0版本中创建每行包含图片的工作表,删除或过滤行时,对应行的图片会残留。尝试过多种图片添加方式,包括设置不同的editAs参数(如oneCell或默认值),均未解决问题,推测可能是缺少“嵌入单元格”功能,或是实现方式有误,恳请提供技术协助。

代码实现:

const workbook = new ExcelJS.Workbook()

const worksheet = workbook.addWorksheet('test')

worksheet.autoFilter = 'A1:D1'
worksheet.views = [{ state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2' }]

worksheet.columns = [
  { header: 'column 1', key: 'col1' },
  { header: 'column 2', key: 'col2' },
  { header: 'column 3', key: 'col3' },
  { header: 'column 4', key: 'col4' },
]

const buffer = Deno.readFileSync('assets/logo.png')
for (let i = 0; i <= 3; i++) {
  const row = worksheet.addRow([i + 1, i + 2, i + 3, ''])
  const imageId = workbook.addImage({
    buffer,
    extension: 'png',
  })
  const imageHeight = 50
  const rowHeight = Math.floor(imageHeight * 0.75)
  worksheet.getRow(row.number).height = rowHeight

  worksheet.addImage(imageId, {
    tl: { col: 3, row: row.number - 1 },
    ext: { width: 100, height: imageHeight },
    editAs: undefined, // tested also with 'oneCell'
  })
}

return await workbook.xlsx.writeBuffer()

操作效果:

  • 操作前:
    操作前
  • 删除行后:
    删除行后

内容的提问来源于stack exchange,提问作者Hamid Shoja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 23:42:09