0

I have applied formula on a cell to calculate sum of the doubles in cells of a row, I want the answer to be printed with symbol pound(GBP).

This is the formula:

Cell cellDynamic = row.createCell(59); cellDynamic.setCellFormula("SUM(J10*$J9+K10*$K$9+L10*$L$9+M10*$M$9+N10*$N$9)");

I have tried to set the cell-style but it does not work:

CellStyle style = workbook.createCellStyle();
cellDynamic.setCellStyle(style.setDataFormat((short)8));

I am getting answer as (for eg) : 225.45, whereas it should be : £225.45

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
dheeraj
  • 1
  • 2
  • Does [this](https://stackoverflow.com/a/27277918/1271785) help? – pfurbacher Mar 09 '23 at 04:53
  • no that did not help , i have used that, it says "The method setCellStyle(CellStyle) in the type Cell is not applicable for the arguments (void)" . – dheeraj Mar 09 '23 at 05:30
  • i have mentioned the formula that i am using to calculate the sum of data inside the cell, using that formula i am getting the expected sum but i need that with a pound symbol – dheeraj Mar 09 '23 at 06:08
  • 2
    `cellDynamic.setCellStyle(style.setDataFormat((short)8));`: That cannot work. It should throw an exception. Do that in two steps: `style.setDataFormat((short)8); cellDynamic.setCellStyle(style);` – Axel Richter Mar 09 '23 at 06:21
  • thank you @AxelRichter , its working , but it is showing dollar symbol, i need pound, can you tell me which short value or anything else that i have to add ? – dheeraj Mar 09 '23 at 06:34
  • It shows the currency symbol which is set in your Windows system (Region settings). If you change that to en_GB, then it will show £. – Axel Richter Mar 09 '23 at 06:59
  • 1
    If you need different currencies in one Excel sheet, see https://stackoverflow.com/questions/67801007/how-to-set-different-currency-in-different-cell-depending-on-currency-code/67816490#67816490 – Axel Richter Mar 09 '23 at 07:30
  • https://stackoverflow.com/questions/67801007/how-to-set-different-currency-in-different-cell-depending-on-currency-code here the answer to your question – Shakirov Ramil Mar 09 '23 at 08:03

0 Answers0