Skip to main content

CalcBuilder Tutorial

Calc Builder 6: the spreadsheet engine

If your logic already lives in an Excel workbook, you do not have to re-implement it in PHP. The Spreadsheet screen lets Calc Builder run the workbook for you.

Spreadsheet screen

Steps

  1. Prepare an .xlsx file with clearly identified input cells and output cells (formulas).
  2. Open the Spreadsheet screen from the toolbar and, on Main, Choose File to upload it. Pick when the calculation launches — Before PHP code if the PHP box stays empty, or At a custom point to place a //[EXCEL] marker inside your PHP code and control exactly when it runs — then leave Use Spreadsheet File Cache off while testing and set the Locale.
  3. Input fields mapping — click Add once per field and fill Variable name → Sheet Number → Cell, e.g. field loan_amount → sheet 0 → B1. “Sheet Number” is the zero-based index of the tab (0 is the first sheet) — not the sheet's name.
  4. Output fields mapping — the same screen, the other direction: Sheet Number → Cell → Variable name, e.g. 0 / B10 → total_interest.

When the visitor calculates, Calc Builder writes the inputs into the workbook, recalculates the formulas and reads the outputs back. Those become plain PHP variables — no $ in the mapping, just the name you typed — available in the PHP code and in the Exit Layout as ##total_interest##.

If an output cell already carries a number format in Excel (e.g. 0.00), Calc Builder returns it already formatted as a ready-to-print string — there is no need to (float) cast it or run it through number_format() in PHP. Set the format once in the workbook, and every place that prints the mapped variable gets it formatted the same way.

You can mix approaches: let the spreadsheet do the heavy maths and use a few lines of PHP to format or to build an HTML summary — or skip PHP entirely and print the mapped variables directly, as the worked example below does.

See it end to end in a loan calculator with an amortization schedule (Excel spreadsheet) — the finance maths is 100% Excel, with only a dozen lines of PHP left to turn its schedule into a table — and compare it with the PHP-code version of the same calculator.

...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!
...
List Manager

Build different lists for your site

Buy now!