Spreadsheet Cross Calculations
You can use Excel-like formulas to perform calculations across different spreadsheet instances. However, note that the sequence in which you load the spreadsheets can cause errors, especially if a formula references a spreadsheet that has yet to be loaded. To handle this scenario, starting from jspreadsheet v10.3.0 and onwards, a feature has been introduced to pause calculations until all spreadsheets are ready.
|
---|
1 | Crayons Crayola only (No Rose Art) | 2 | 5.13 | 10.26 |
2 | Colored Pencils Crayola only | 2 | 4.41 | 8.82 |
3 | Expo Dry-erase Markers Wide | 4 | 3 | 12 |
4 | Index Cards Unlined | 3 | 6 | 18 |
5 | Tissues | 10 | 1.9 | 19 |
6 | Ziploc Sandwich-size Bags | 5 | 1 | 5 |
7 | Thin Markers Crayola only | 2 | 3 | 6 |
8 | Highlighter | 4 | 1.2 | 4.8 |
9 | Total | 32 | 25.64 | 83.88 |
|
---|
1 | Price | 83.88 |
2 | Discount | 10 |
3 | Total | 75.492 |
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<div id="spreadsheet1"></div><br><br>
<div id="spreadsheet2"></div>
<script>
jspreadsheet.setLicense('ZWNmYWEzNmIwOWRkMTZlM2JmZTQzMThkZmNkMTg1Y2EyZDgwZjNlNGRjN2NlZTk2MGZhZDFiMjQ0Mjc2NmM4NTUyYzYyOWQ0MzliNDdlNDczNjlmNzQ0NDM4YjU0NTZiNjQ1MWEyOWRkZWZhYWNlNTIwYzM3YTI4NWQ0NTk2MzEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNMk5EZzBOVGs1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
jspreadsheet.calculations(false);
jspreadsheet(document.getElementById('spreadsheet1'), {
worksheets: [{
data: [
[ 'Crayons Crayola only (No Rose Art)', 2, 5.13, '=B1*C1' ],
[ 'Colored Pencils Crayola only', 2, 4.41, '=B2*C2' ],
[ 'Expo Dry-erase Markers Wide', 4, 3.00, '=B3*C3' ],
[ 'Index Cards Unlined', 3, 6.00, '=B4*C4' ],
[ 'Tissues', 10, 1.90, '=B5*C5' ],
[ 'Ziploc Sandwich-size Bags', 5, 1.00, '=B6*C6' ],
[ 'Thin Markers Crayola only', 2, 3.00, '=B7*C7' ],
[ 'Highlighter', 4, 1.20, '=B8*C8' ],
[ 'Total', '=SUM(B1:B8)', '=ROUND(SUM(C1:C8), 2)', '=SUM(D1:D8)' ],
],
columns: [
{ type: 'text', title:'Product', width:'300' },
{ type: 'number', title:'Qtd', width:'80' },
{ type: 'number', title:'Price', width:'100' },
{ type: 'number', title:'Total', width:'100' },
],
worksheetName: 'Products',
columnSorting: false,
}],
});
jspreadsheet(document.getElementById('spreadsheet2'), {
worksheets: [{
data: [
[ 'Price', '=SUM(Products!D1:D8)'],
[ 'Discount', 0.1],
[ 'Total', '=B1*(1-B2)'],
],
columns: [
{ type: 'text', title:'Summary', width:'300' },
{ type: 'number', title:'Total', width:'200' },
],
cells: { B2: { type:'percent' } },
columnSorting: false,
}],
});
jspreadsheet.calculations(true);
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
jspreadsheet.setLicense('ZWNmYWEzNmIwOWRkMTZlM2JmZTQzMThkZmNkMTg1Y2EyZDgwZjNlNGRjN2NlZTk2MGZhZDFiMjQ0Mjc2NmM4NTUyYzYyOWQ0MzliNDdlNDczNjlmNzQ0NDM4YjU0NTZiNjQ1MWEyOWRkZWZhYWNlNTIwYzM3YTI4NWQ0NTk2MzEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNMk5EZzBOVGs1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
jspreadsheet.setExtensions({ formula })
export default function App() {
const productsRef = useRef();
const summaryRef = useRef();
const products = {
worksheets: [{
data: [
[ 'Crayons Crayola only (No Rose Art)', 2, 5.13, '=B1*C1' ],
[ 'Colored Pencils Crayola only', 2, 4.41, '=B2*C2' ],
[ 'Expo Dry-erase Markers Wide', 4, 3.00, '=B3*C3' ],
[ 'Index Cards Unlined', 3, 6.00, '=B4*C4' ],
[ 'Tissues', 10, 1.90, '=B5*C5' ],
[ 'Ziploc Sandwich-size Bags', 5, 1.00, '=B6*C6' ],
[ 'Thin Markers Crayola only', 2, 3.00, '=B7*C7' ],
[ 'Highlighter', 4, 1.20, '=B8*C8' ],
[ 'Total', '=SUM(B1:B8)', '=ROUND(SUM(C1:C8), 2)', '=SUM(D1:D8)' ],
],
columns: [
{ type: 'text', title:'Product', width:'300' },
{ type: 'number', title:'Qtd', width:'80' },
{ type: 'number', title:'Price', width:'100' },
{ type: 'number', title:'Total', width:'100' },
],
worksheetName: 'Products',
columnSorting: false,
}],
};
const summary = {
worksheets: [{
data: [
[ 'Price', '=SUM(Products!D1:D8)'],
[ 'Discount', 0.1],
[ 'Total', '=B1*(1-B2)'],
],
columns: [
{ type: 'text', title:'Summary', width:'300' },
{ type: 'number', title:'Total', width:'200' },
],
cells: { B2: { type:'percent' } },
columnSorting: false,
}],
}
return (
<Spreadsheet ref={summaryRef} worksheets={summary.worksheets} />
<Spreadsheet ref={productsRef} worksheets={products.worksheets} />
);
}
<template>
<Spreadsheet :worksheets="summary" />
<Spreadsheet :worksheets="products" />
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
jspreadsheet.setLicense('ZWNmYWEzNmIwOWRkMTZlM2JmZTQzMThkZmNkMTg1Y2EyZDgwZjNlNGRjN2NlZTk2MGZhZDFiMjQ0Mjc2NmM4NTUyYzYyOWQ0MzliNDdlNDczNjlmNzQ0NDM4YjU0NTZiNjQ1MWEyOWRkZWZhYWNlNTIwYzM3YTI4NWQ0NTk2MzEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNMk5EZzBOVGs1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==');
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
const products = [
{
data: [
["Crayons Crayola only (No Rose Art)", 2, 5.13, "=B1*C1"],
["Colored Pencils Crayola only", 2, 4.41, "=B2*C2"],
["Expo Dry-erase Markers Wide", 4, 3.0, "=B3*C3"],
["Index Cards Unlined", 3, 6.0, "=B4*C4"],
["Tissues", 10, 1.9, "=B5*C5"],
["Ziploc Sandwich-size Bags", 5, 1.0, "=B6*C6"],
["Thin Markers Crayola only", 2, 3.0, "=B7*C7"],
["Highlighter", 4, 1.2, "=B8*C8"],
["Total", "=SUM(B1:B8)", "=ROUND(SUM(C1:C8), 2)", "=SUM(D1:D8)"],
],
columns: [{
type: "text",
title: "Product",
width: "300"
},
{
type: "number",
title: "Qtd",
width: "80"
},
{
type: "number",
title: "Price",
width: "100"
},
{
type: "number",
title: "Total",
width: "100"
},
],
worksheetName: "Products",
columnSorting: false,
}
];
const summary = [
{
data: [
["Price", "=SUM(Products!D1:D8)"],
["Discount", 0.1],
["Total", "=B1*(1-B2)"],
],
columns: [{
type: "text",
title: "Summary",
width: "300"
},
{
type: "number",
title: "Total",
width: "200"
},
],
cells: {
B2: {
type: "percent"
}
},
columnSorting: false,
}
];
return {
products,
summary,
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import "jspreadsheet/dist/jspreadsheet.css"
import "jsuites/dist/jsuites.css"
jspreadsheet.setLicense('ZWNmYWEzNmIwOWRkMTZlM2JmZTQzMThkZmNkMTg1Y2EyZDgwZjNlNGRjN2NlZTk2MGZhZDFiMjQ0Mjc2NmM4NTUyYzYyOWQ0MzliNDdlNDczNjlmNzQ0NDM4YjU0NTZiNjQ1MWEyOWRkZWZhYWNlNTIwYzM3YTI4NWQ0NTk2MzEsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpNMk5EZzBOVGs1TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0ozWldJaUxDSnNiMk5oYkdodmMzUWlYU3dpY0d4aGJpSTZJak0wSWl3aWMyTnZjR1VpT2xzaWRqY2lMQ0oyT0NJc0luWTVJaXdpZGpFd0lpd2lkakV4SWl3aVkyaGhjblJ6SWl3aVptOXliWE1pTENKbWIzSnRkV3hoSWl3aWNHRnljMlZ5SWl3aWNtVnVaR1Z5SWl3aVkyOXRiV1Z1ZEhNaUxDSnBiWEJ2Y25SbGNpSXNJbUpoY2lJc0luWmhiR2xrWVhScGIyNXpJaXdpYzJWaGNtTm9JaXdpY0hKcGJuUWlMQ0p6YUdWbGRITWlMQ0pqYkdsbGJuUWlMQ0p6WlhKMlpYSWlMQ0p6YUdGd1pYTWlYU3dpWkdWdGJ5STZkSEoxWlgwPQ==')
@Component({
standalone: true,
selector: "app-root",
template: `
<div #summary></div>
<div #products></div>
`,
})
export class AppComponent {
@ViewChild("summary") summary: ElementRef;
@ViewChild("products") products: ElementRef;
worksheets: jspreadsheet.worksheetInstance[];
ngAfterViewInit() {
jspreadsheet.calculations(false);
jspreadsheet(this.summary.nativeElement, {
worksheets: [{
data: [
[ 'Crayons Crayola only (No Rose Art)', 2, 5.13, '=B1*C1' ],
[ 'Colored Pencils Crayola only', 2, 4.41, '=B2*C2' ],
[ 'Expo Dry-erase Markers Wide', 4, 3.00, '=B3*C3' ],
[ 'Index Cards Unlined', 3, 6.00, '=B4*C4' ],
[ 'Tissues', 10, 1.90, '=B5*C5' ],
[ 'Ziploc Sandwich-size Bags', 5, 1.00, '=B6*C6' ],
[ 'Thin Markers Crayola only', 2, 3.00, '=B7*C7' ],
[ 'Highlighter', 4, 1.20, '=B8*C8' ],
[ 'Total', '=SUM(B1:B8)', '=ROUND(SUM(C1:C8), 2)', '=SUM(D1:D8)' ],
],
columns: [
{ type: 'text', title:'Product', width:'300' },
{ type: 'number', title:'Qtd', width:'80' },
{ type: 'number', title:'Price', width:'100' },
{ type: 'number', title:'Total', width:'100' },
],
worksheetName: 'Products',
columnSorting: false,
}],
});
jspreadsheet(this.products.nativeElement, {
worksheets: [{
data: [
[ 'Price', '=SUM(Products!D1:D8)'],
[ 'Discount', 0.1],
[ 'Total', '=B1*(1-B2)'],
],
columns: [
{ type: 'text', title:'Summary', width:'300' },
{ type: 'number', title:'Total', width:'200' },
],
cells: { B2: { type:'percent' } },
columnSorting: false,
}],
});
jspreadsheet.calculations(true);
}
}