审计审查中跨sheet页单元格数据关联实现
在审计过程中,我们经常会遇到将某个sheet页中的部分数据选择出来进行审计,如将下表中的床箱和床头柜选出来进行数量和单价的审计,审计效果如下:
接下来我分享一些这块如何实现:
1,给原表sheet1的行添加tag:
let rows = sheet.getRowCount();
for (let i = 0; i + 2 < rows; i++) {
sheet.setTag(i + 2, -1, `${i}`);
}2.对用户选择的行进行数据的过滤:var selections = sheet.getSelections();
if (!selections || selections.length === 0) {
return;
}
for (let i = 0; i < selections.length; i++) {
row = selections.row;
col = selections.col;
if (col === -1 && row !== -1) {
selects.push(parseInt(sheet.getTag(row, col)));
}
}
let templateConfigData = [];
for (let i = 0; i < selects.length; i++) {
templateConfigData.push(dataSource])
}3.将过滤后的数据通过数据绑定进行展示,并配置汇总公式:
let data1 = { dataSource1: templateConfigData };
let sheet1 = spread.getSheetFromName("Sheet2");
let table1 = sheet1.tables.all();
table1.autoGenerateColumns(false);
table1.setColumnFormula(0, `SUBTOTAL(109,[数量])`)
sheet1.defaults.rowHeight = 50;
// table.set
var tableColumnNew1 = new spreadNS.Tables.TableColumn();
tableColumnNew1.dataField("quantity");
tableColumnNew1.name("数量");
var tableColumnNew2 = new spreadNS.Tables.TableColumn();
tableColumnNew2.dataField("unitPrice");
tableColumnNew2.name("单价");
table1.bindColumns();
table1.bindingPath('dataSource1');
let dataSource2 = new spreadNS.Bindings.CellBindingSource(data1);
spread.getSheet(1).setDataSource(dataSource2);详细代码见附录:
页:
[1]