[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
SpreadJS通过允许用户显示公式与单元格之间的关系,为公式审核提供了广泛的支持。 这可以通过跟踪表单中的先例单元格和从属单元格来完成。
在使用表单时,公式审核可帮助用户识别计算瓶颈,调试公式并验证结果的准确性。 此外,此功能还可以帮助用户:
Maintain Regulatory Compliance -在处理财务,会计和其他复杂应用程序时,公式审核功能对于保持合规性很有用。
Check Errors - 公式审核可帮助用户识别错误的来源,否则这将是极其困难的任务,尤其是在表单中的公式使用先行或从属单元格的情况下。
Locate Circular References - 通过公式审核,用户可以通过跟踪表单中的先例和从属关系来快速找到所有循环引用,以节省时间。
Detect Inconsistency - 在大型表单中,用户可以推测列中公式中的任何不一致之处,而不必在验证数据时手动查看每个公式。
先例单元格是位于另一个单元格中的公式所引用的单元格。 从属单元格是包含公式并引用其他单元格的单元格。
例如,如果单元格D10包含公式“ = B5”,则单元格B5将被视为单元格D10的先例,而单元格D10将被视为单元格B5的从属。
在审核表单中的公式时,可以使用 getPrecedents
方法跟踪先例,并使用 getDependents
方法跟踪从属关系以可视化并显示与所选公式单元格相关的单元格。
例如-假设您正在开发一个金融或银行应用程序,其中使用表单中的公式分析每月交易(贷方 & 借方),并为每个客户生成每月报告。 在这种情况下,单个评估错误会直接导致损失,因此,在与客户共享每月会计报表之前,审核公式成为前提。
下图说明了一个小型金融应用程序,其中使用公式为每笔交易计算余额,并且在单击最后一列中的任何单元格时,将突出显示先行单元格和从属单元格。
下面的示例代码突出显示表单中的前例单元和从属单元。
<script type="text/javascript">
var oldPrecedentCells, oldDependentCells;
$(document).ready(function () {
// 初始化 Spread
var spread = new GC.Spread.Sheets.Workbook($("#sampleDiv")[0], { autoFitType: GC.Spread.Sheets.AutoFitType.cellWithHeader });
// 设置表单的数据源
var jsonArray = [
{
" DATE ": " 3-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL28091 ",
" WITHDRAWAL AMOUNT ": 12106.00,
" DEPOSIT AMOUNT ": 1000000.00,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 3-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL29091 ",
" WITHDRAWAL AMOUNT ": 12611.00,
" DEPOSIT AMOUNT ": 1000000.0,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 5-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL04101 ",
" WITHDRAWAL AMOUNT ": 61400.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 16-Oct-17 ",
" TRANSACTION DETAILS ": " FDRL/INTERNAL FUND TRANSFE ",
" WITHDRAWAL AMOUNT ": null,
" DEPOSIT AMOUNT ": 500000.00,
" BALANCE AMOUNT ": "",
},
{
" DATE ": " 17-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL06101 ",
" WITHDRAWAL AMOUNT ": 6000.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": "",
},
{
" DATE ": " 17-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL07101 ",
" WITHDRAWAL AMOUNT ": 97950.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 18-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL17101 ",
" WITHDRAWAL AMOUNT ": 206501.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 21-Oct-17 ",
" TRANSACTION DETAILS ": " FDRL/INTERNAL FUND TRANSFE ",
" WITHDRAWAL AMOUNT ": null,
" DEPOSIT AMOUNT ": 500000.00,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 23-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL21101 ",
" WITHDRAWAL AMOUNT ": 39000.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 26-Oct-17 ",
" TRANSACTION DETAILS ": " INDO GIBL Indiaforensic STL25101 ",
" WITHDRAWAL AMOUNT ": 170125.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 27-Oct-17 ",
" TRANSACTION DETAILS ": "INDO GIBL Indiaforensic STL26101",
" WITHDRAWAL AMOUNT ": 208000.00,
" DEPOSIT AMOUNT ": null,
" BALANCE AMOUNT ": ""
},
{
" DATE ": " 30-Oct-17 ",
" TRANSACTION DETAILS ": " FDRL/INTERNAL FUND TRANSFE ",
" WITHDRAWAL AMOUNT ": null,
" DEPOSIT AMOUNT ": 500000.00,
" BALANCE AMOUNT ": ""
}
];
var activeSheet = spread.getActiveSheet();
activeSheet.setDataSource(jsonArray);
// 配置表单设置
activeSheet.getRange(0, 2, 12, 3).formatter('* #.00');
for (var c = 0; c < activeSheet.getColumnCount(); c++)
{
activeSheet.autoFitColumn(c);
}
// 设置单元格公式
activeSheet.setFormula(0, 4, "D2");
for (var r = 1; r < activeSheet.getRowCount(); r++) {
activeSheet.setFormula(r, 4, "E" + r.toString() + "+ D" + (r + 1).toString() + "- C" + (r + 1).toString());
}
// 跟踪活动单元的前例和从属
activeSheet.bind(GC.Spread.Sheets.Events.SelectionChanging, function (e, info)
{
spread.suspendPaint();
var newRow = info.newSelections[0].row;
var newCol = info.newSelections[0].col;
ColorPrecedents(activeSheet, newRow, newCol);
ColorDependents(activeSheet, newRow, newCol);
spread.resumePaint();
});
});
// 将先例单元格绘制黄色
function ColorPrecedents(sheet, row, col)
{
if (oldPrecedentCells)
{
oldPrecedentCells.forEach(function (node)
{
sheet.getCell(node.row, node.col).backColor(undefined);
});
}
var precedentCells = sheet.getPrecedents(row, col);
if (precedentCells)
{
setTimeout(function ()
{
oldPrecedentCells = precedentCells;
precedentCells.forEach(function (node) {
sheet.getCell(node.row, node.col).backColor("yellow");});}, 10);
}
}
// 将依赖的单元格绘制绿色
function ColorDependents(sheet, row, col)
{
if (oldDependentCells)
{
oldDependentCells.forEach(function (node) {
sheet.getCell(node.row, node.col).backColor(undefined);
});
}
var dependentCells = sheet.getDependents(row, col);
oldDependentCells = dependentCells;
if (dependentCells) {
dependentCells.forEach(function (node) {
sheet.getCell(node.row, node.col).backColor("green");
});
}
}
</script>