SpreadJS Documentation > Sample Code > Sample Code for Formulas > Using Subtotals |
You can use subtotals in rows.
This example uses a subtotal formula.
JavaScript |
Copy Code
|
---|---|
$(document).ready(function () { var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3}); var activeSheet = spread.getActiveSheet(); activeSheet.setColumnCount(2); activeSheet.setColumnHeaderAutoText(GcSpread.Sheets.HeaderAutoText.blank); activeSheet.setText(0, 1, "Value", GcSpread.Sheets.SheetArea.colHeader); activeSheet.setGridlineOptions({showHorizontalGridline: false}); activeSheet.setText(3, 0, "Sub-Total1"); activeSheet.setText(7, 0, "Sub-Total2"); activeSheet.setText(8, 0, "Aggregate"); activeSheet.getRow(3).backColor("lemonChiffon"); activeSheet.getRow(7).backColor("lemonChiffon"); activeSheet.getRow(8).backColor("lightPink"); activeSheet.setValue(0, 1, 100); activeSheet.setValue(1, 1, 200); activeSheet.setValue(2, 1, 300); activeSheet.setValue(4, 1, 400); activeSheet.setValue(5, 1, 500); activeSheet.setValue(6, 1, 600); //Set the sub-total and the aggregate by using SUBTOTAL function. activeSheet.setFormula(3, 1, "SUBTOTAL(9,B1:B3)"); activeSheet.setFormula(7, 1, "SUBTOTAL(9,B5:B7)"); activeSheet.setFormula(8, 1, "SUBTOTAL(9,B1:B7)"); }); |