其实这块的代码量非常小,前面已经给出了具体的实现方案,只需要用代码写出来就好了~
- // 添加一些假数据
- sheet.setValue(1, 1, 1)
- sheet.setValue(1, 2, 2)
- sheet.setValue(2, 1, 3)
- sheet.setValue(2, 2, 4)
- let style = new GC.Spread.Sheets.Style()
- style.backColor = "red"
- style.fontWeight = "bold"
- style.foreColor = "yellow"
- sheet.getRange(1, 1, 2, 2).setStyle(style)
- // 暂停绘制,防止区域快照出现在页面中
- sheet.suspendPaint()
- // 添加区域快照
- let cameraShape = sheet.shapes.addCameraShape("camerashape1", "Sheet1!B2:C3")
- // 拿到区域快照的图像
- let imgSrc = cameraShape.toImageSrc()
- // 移除区域快照
- sheet.shapes.remove("camerashape1")
- // 添加图片
- let picture = sheet.shapes.addPictureShape("picture1", imgSrc)
- // 设置图片的位置和B5:C6重合
- picture.startRow(4)
- picture.endRow(5)
- picture.startColumn(1)
- picture.endColumn(2)
- sheet.resumePaint()
复制代码
|