使用Spire.XSL插入图形,可以直接向Worksheet中的Pictures中插入,示例代码如下:
sheet.Pictures.Add(topRow, leftCol, rightRow, buttonCol, path);
path是需要插入图形的路径。topRow, leftCol, rightRow, buttonCol分别为图片需要占用的区域。
如果插入原始大小,可以忽略右下的参数:
sheet.Pictures.Add(topRow, leftCol, path);
也可以直接插入图像对象,比如已经存在Image image:
sheet.Pictures.Add(topRow, leftCol, image);
还可以从流中插入对象,比如已经存在Stream stream:
sheet.Pictures.Add(topRow, leftCol, stream);
如果需要设置插入图片的宽和高,参数的顺序如下:
sheet.Pictures.Add(topRow, leftCol, path,width,height);