Formula Support
Introduction

This document describes the current state of formula support in POI. The information in this document applies to the 2.0-dev version of POI (i.e. CVS HEAD). Since this area is a work in progress, this document will be updated with new features as and when they are added.

The basics

In org.apache.poi.hssf.usermodel.HSSFCell setCellFormula("formulaString") is used to add a formula to sheet and getCellFormula() is used to retrieve the string representation of a formula.

We aim to support the complete excel grammer for formulas. Thus, the string that you pass in to the setCellFormula call should be what you expect to type into excel. Also, note that you should NOT add a "=" to the front of the string.

Supported Features
Partially supported
Not yet supported
Internals

Formulas in Excel are stored as sequences of tokens in Reverse Polish Notation order. The open office XLS spec is the best documentation you will find for the format.

The tokens used by excel are modelled as individual *Ptg classes in the org.apache.poi.hssf.record.formula package.

The task of parsing a formula string into an array of RPN ordered tokens is done by the org.apache.poi.hssf.record.formula.FormulaParser class. This class implements a hand written recursive descent parser.

Check out the javadocs for details.