Documentation Buy Contact Blog
Formula Example

It's super easy to add or read formulas from your Excel spreadsheets. They are just strings the same as you would type into Excel itself.

This is what your final result will look like
This is what your final result will look like.

In the code below you can see that the cells in the B column are just simple strings, while the C column has formulas set.

Select your language below to view the source. You can download Number Duck here, along with the source and binaries for this example.

C++ PHP
C++
printf("Formula Example\n");
printf("Create a spreadsheet with formulas!\n\n");

Workbook workbook("");
Worksheet* pWorksheet = workbook.GetWorksheetByIndex(0);
	
for (uint16_t i = 0; i < 5; i++)
{
	Cell* pCell = pWorksheet->GetCell(0, i);
	pCell->SetFloat(i * 2.34f);
}

pWorksheet->GetCell(1,0)->SetString("=SUM(A1:A5)");
pWorksheet->GetCell(1,1)->SetString("=AVERAGE(A1:A5)");

pWorksheet->GetCell(2,0)->SetFormula("=SUM(A1:A5)");
pWorksheet->GetCell(2,1)->SetFormula("=AVERAGE(A1:A5)");

	
workbook.Save("FormulaExample.xls");

Workbook* pWorkbookIn = new Workbook("");
if (pWorkbookIn->Load("FormulaExample.xls"))
{
	Worksheet* pWorksheetIn = pWorkbookIn->GetWorksheetByIndex(0);
	Cell* pCellIn = pWorksheetIn->GetCell(2,1);
	printf("Formula: %s\n", pCellIn->GetFormula());
}