We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

getStringValue() works unexpeceted

Hello.


In my example i want to replace certain cell’s formula to it’s value. It works, when worsheet’s flag “Display Zeros” is true, but don’t works, when this flag is false.

@Test
public void removeFormulaTest() {
Workbook wb = new Workbook();
Worksheet ws = wb.getWorksheets().get(0);
ws.setDisplayZeros(false);

Cell cell = ws.getCells().get(1, 1);

ws.getCells().get(0,0).setValue(0);

cell.setFormula("=A1+A2");

wb.calculateFormula();

assertEquals(0.0, cell.getValue());

String value = cell.getStringValue();
assertEquals(“0”, value);

cell.putValue(value, true);
}

I expected, that getStringValue() returns zeros too (getDisplayStringValue() should not).

Can you please help me with this issue? May be there is exists some way to replace formula by it’s value?

Best regards. Alexey

Hi Alexey,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue after executing your code with the latest version. Cell.getStringValue() should return 0 for cell B2, but it is returning an empty string.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40888.

Hi,



We have evaluated your issue further. Well, Cell.getStringValue() for numeric values is designed to give the result a user can get when copying cell’s value as text. For zero value with DisplayZeros=false, the text you can get from MS Excel when copying this cell is also empty. To get the actual value, please use Cell.getValue() instead. And for your requirement that replacing formulas with the calculated value, there is another convenient API, i.e., Cells.removeFormulas() that you may use it.

Thank you.

Hello. Thank for reply. There is exists a way for remove formula for specified cell (not all)?

Hi,


Well, I am afraid there is no such API but you may try to use:
e.g
Sample code:

cell.putValue(cell.getValue().toString());

Thank you.