POI use excel function

was writing some xls file processing code need to use excel build in function XIRR

Need to use Cell’s setCellType to CELL_TYPE_FORMULA

Then setCellFormula

 

sample code:

            String formula = "XIRR(" + sourceSheetNameWithSingleQuote + "!C" + excelStartRow + ":" + sourceSheetNameWithSingleQuote + "!C" + excelEndRow + "," +
                sourceSheetNameWithSingleQuote + "!B" + excelStartRow +
                ":" + sourceSheetNameWithSingleQuote + "!B" + excelEndRow + ")";
            Cell cell = resultSheet.getRow(fundCount).createCell(1);
            cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
            cell.setCellFormula(formula);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s