Formulas

Master Excel formulas - cell references, built-in functions, and complex calculations

Learn how to add formulas and calculations to your spreadsheets using the BoxLang Fluent API. This guide covers everything from basic arithmetic to complex Excel functions.


📝 Formula Basics

Adding Simple Formulas

Spreadsheet( "calculations.xlsx" )
    .setRowData( 1, [ "Price", "Quantity", "Total" ] )
    .setCellValue( 2, 1, 29.99 )
    .setCellValue( 2, 2, 5 )

    // Add formula
    .setCellFormula( 2, 3, "A2*B2" )

    .save();

Reading Formulas

sheet = Spreadsheet( "with-formulas.xlsx" );

// Get formula text
formula = sheet.getCellFormula( 2, 3 );  // Returns: "A2*B2"

// Get calculated value
value = sheet.getCellValue( 2, 3 );      // Returns: 149.95

// Get cell type
type = sheet.getCellType( 2, 3 );        // Returns: "formula"

Recalculating Formulas


🔤 Cell References

Relative References

Absolute References

Mixed References

Range References


➕ Arithmetic Operations

Basic Operations

Order of Operations


📊 Common Excel Functions

SUM Functions

AVERAGE, MIN, MAX

COUNT Functions

IF Function

SUMIF and COUNTIF

VLOOKUP

TEXT Functions

DATE Functions


🔗 Cross-Sheet Formulas

Referencing Other Sheets

Complex Cross-Sheet Calculations


🎯 Formula Patterns

Running Totals

Percentage Calculations

Variance Analysis

Ranking


🔧 Formula Helpers

Using BoxLang to Generate Formulas

Dynamic Range Formulas


⚠️ Formula Tips

String Escaping in Formulas

When formulas contain quotes, use proper escaping:

Error Handling

Array Formulas

Some Excel formulas work with arrays:


📚 Next Steps

Advanced FeaturesExamplesFluent API

Last updated

Was this helpful?