你可以在公式内使用RANGEBLOCKSPARKLINE函数来创建区域模板迷你图:=RANGEBLOCKSPAKLINE(template_range, data_expr)。
函数具有以下的参数:
template_range: 代表模板范围的引用,比如Template!A1:E10。
data_expr: 单元格引用或者OBJECT函数的结果,表示模板绑定的对象数据,例如A1或者OBJECT(E4:AB4, E5:AB5).
例如:
对于OBJECT函数,你可以在公式中用OBJECT函数创建一个对象:
=OBJECT(prop1, expr1, prop2, expr2, …) // the 1->1 case
或 =OBJECT(props_range, exprs_range) // the n1->n2 case
或 =OBJECT(property1, expressionArray1, property2, expressionArray2, …) // the 1->n case。
它定义了一个对象,并且参数必须是键值顺序,且成对出现。
属性与值支持一对一,一对多,多对多(属性与值数量必须相等)。
一对一和多对多的情况会返回一个对象,一对多的情况返回一个数组。
例如:
var spreadNS = GC.Spread.Sheets;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 3 });
spread.options.allowDynamicArray = true;
initSpread(spread);
};
function initSpread(spread) {
var renderSheet = spread.getSheet(0);
var templateSheet = spread.getSheet(1);
var dataSheet = spread.getSheet(2);
spread.options.scrollByPixel = true;
spread.options.scrollPixel = 10;
spread.suspendPaint();
initTemplateSheet(templateSheet);
initDataSheet(dataSheet);
initRenderSheet(renderSheet);
spread.resumePaint();
}
function initRenderSheet (renderSheet) {
renderSheet.name("RenderSheet");
renderSheet.setColumnCount(50);
renderSheet.setColumnWidth(0, 1200);
renderSheet.getCell(0, 0).value("Top 5 Products (by units sold)")
.font("20px Arial").vAlign(GC.Spread.Sheets.VerticalAlign.center)
.foreColor("white").backColor("#82bc00");
renderSheet.setRowHeight(0, 35);
for (var i = 1; i < 6; i++) {
renderSheet.setRowHeight(i, 250);
renderSheet.setFormula(i, 0, 'RANGEBLOCKSPARKLINE(TemplateSheet!A2:M11, OBJECT(product_table[#Headers], INDEX(product_table[#Data],ROW()-1,SEQUENCE(COUNTA(product_table[#Headers]),1))))');
}
}
function initTemplateSheet (templateSheet) {
templateSheet.fromJSON(templateJson);
templateSheet.name("TemplateSheet");
templateSheet.setFormatter(2,1,"=IMAGE(\"$DEMOROOT$/spread/source/images/products/\"&@)");
templateSheet.setBindingPath(2,1,"Image");
}
function initDataSheet (dataSheet) {
dataSheet.fromJSON(dataJson);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="zh-cn" />
<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$/spread/source/js/license.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/range-block-data.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/data/range-block-template.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="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;
}