你可以使用IMAGE函数来创建一个图片:=IMAGE(source,alt_text,sizing,height,width,clipX,clipY,clipHeight,clipWidth,vAlign,hAlign)。
此函数拥有以下参数:
source: 图片的URL,引用或者base64字符串.
alt_text: (可选) 用以描述图像的替代文本.
sizing: (可选) 数字类型,代表图像填充类型,可用选项:
保持长宽比填充 - 0
图片完全填充 - 1
原始尺寸填充 - 2
定制尺寸填充 - 3
height: (可选) 如果mode是3,代表图像的高度。
width: (可选) 如果mode是3,代表图像的宽度。
clipX: (可选) 需要绘制到目标区域中的,image的矩形(裁剪)选择框的左上角 X 轴坐标。
clipY: (可选) 需要绘制到目标区域中的,image的矩形(裁剪)选择框的左上角 Y 轴坐标。
clipHeight: (可选) 需要绘制到目标区域中的,image的矩形(裁剪)选择框的高度。
clipWidth: (可选) 需要绘制到目标区域中的,image的矩形(裁剪)选择框的宽度。
vAlign: (可选) 这个值指代图像的垂直对齐方式。可选项:
顶部 - 0
居中 - 1
底部 - 2
hAlign: (可选) 这个值指代图像的水平对齐方式。可选项:
左边 - 0
水平居中 - 1
右边 - 2
window.onload = () => {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
}
function initSpread(spread) {
spread.suspendPaint();
spread.fromJSON(data[0]);
spread.options.allowDynamicArray = true;
var sheet = spread.getActiveSheet();
sheet.name("Image Formula");
initImageFormula(sheet);
spread.resumePaint();
}
function initImageFormula(sheet) {
sheet.setFormula(1, 1, '=XLOOKUP(A2,Product_list[ITEM],Product_list[IMAGE])');
sheet.setFormula(5, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image13.jpg", "Wellington boots")');
sheet.setFormula(6, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image4.jpg", "Dress")');
sheet.setFormula(7, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image5.png", "Glasses")');
sheet.setFormula(8, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image6.jpg", "Hat")');
sheet.setFormula(9, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image7.png", "Jacket")');
sheet.setFormula(10, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image8.jpg", "Shorts")');
sheet.setFormula(11, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image9.jpg", "Slippers")');
sheet.setFormula(12, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image10.jpg", "Suitcase")');
sheet.setFormula(13, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image11.png", "Swimsuit")');
sheet.setFormula(14, 4, '=IMAGE("$DEMOROOT$/spread/source/images/avatar/image12.jpg", "T-shirt")');
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="spreadjs culture" content="zh-cn" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js"
type="text/javascript"></script>
<script
src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js"
type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/image-function.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" style="width:100%;height:100%"></div>
</div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}