How To Use Formulas on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
Now we will learn how to Use Formulas on Excel Sheet Using JExcel APIs.
For creating a Formula cell within a worksheet using the JExcel API, the first thing to do is to import the jxl.write.Formula class, whose syntax is given by,
public class Formula extends jxl.write.biff.FormulaRecord implements WritableCell
It creates a cell , created by user applications that contains a numerical formula value. The Formula class have two constructors which are used, are as follows :
Formula(int col, int row, String formula)
This constructor of Formula class constructs the formula at the specifed column and row.
Formula(int col, int row, String form, CellFormat st)
This constructor constructs a formula at the specified column and row by wrapping it with appropriate cell format.
The following code snippet will show you how to add a Formula cell to to your working sheet.
Formula fmla=new Formula(3, 1, "SUM(B2:C2)", wcfmuls);
sheet.add(fmla);
The above line creates a Formula class object fmla, and in the constructor of the Formula class we have passed the column and row value, and defined a Formula i.e. SUM(B2:C2) in string format which adds the two cells
and put the value of the sum in the specified cell.
Previous | Home | Next |