Java Aspose cells formatting

HI All,

Issue 1 . it seems like Aspose doesn’t support formatting style selected as shown below. Where we want negative number to be shown as negative without any decorations.

For example

-$4000 to be shown as -$4000 and cell value will be -4000.

Aspose supports only two styles.

-$4000 to be shown as ($4000). And -$4000 to be shown as $4000.

Here is the link on how to set style.

Issue 2 Float value , when we put float value and set style as % with 2 decimal points, the value in the cell changes .Example : 4% is put as 3.9999000567%

Hi,


1) and 2).
I have tested your scenario using the following sample code, it works absolutely fine with our latest version/ fix v8.0.0. I simply input some values and apply numbers formatting accordingly which works fine. Please refer to the following sample code for your reference:
e.g
Sample code:

//Instantiating a Workbook object
Workbook workbook = new Workbook();

//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();

//Adding the current system date to “A1” cell
Cell cell = cells.get(“A1”);
cell.setValue(0.04567);

//Setting the display format of the value as percentage
Style style = cell.getStyle();
style.setCustom(“0.00%”);
cell.setStyle(style);

//Adding a numeric value to “A2” cell
cell = cells.get(“A2”);
cell.setValue(-4000);

style = cell.getStyle();
style.setCustom("$#,##0");
cell.setStyle(style);

//Saving the Excel file.
workbook.save(“out1.xlsx”);

If you still find the issue, kindly paste your sample code here, we will check it soon. Also provide your template file(s) here.

Thank you.

Hi All,

We are still having this problem. Below is our code.

Style cellStyle = workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).getStyle();

//cellStyle.setNumber(5);

cellStyle.setCustom("0.00%");

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0)

.setStyle(cellStyle);

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0)

.putValue(*getFloat*("4"));

private static Float getFloat(String string) {

Float returnValue = **null** ;

returnValue = Float.*valueOf*(string) / 100;

return returnValue;

}

Hi,


I could not spot the issue using your sample code. I tested the following sample code and it works fine. I have attached the output Excel file and screen shot here for your reference.
e.g
Sample code:

Workbook workbook = new Workbook();

} catch (Exception e) {

e.printStackTrace();

}

Style cellStyle = workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).getStyle();

cellStyle.setCustom(“0.00%”);

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).setStyle(cellStyle);

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).putValue(getFloat(“4”));

try {

workbook.save(“out1.xlsm”);

} catch (Exception e) {

e.printStackTrace();

} finally {

System.out.println(“File Generated successfully!”);

}

}

private static Float getFloat(String string) {

Float returnValue = null;

returnValue = Float.valueOf(string) / 100;

return returnValue;

}


Thank you.

We have resolved Issue 1.

For issue 2 I can still see the same in your output file.

**Issue 2 **

Float value

When I put float value and set style as % with 2 decimal points, the value in the cell changes

Example : 4% is put as 3.9999000567%

Example code is in the attached file.

Thanks,

Hiren

Hi,


Did you see my previous attached screen shot, you may confirm it displays value i.e., “4.00%” fine into MS Excel 2007/2010. I am afraid, I could not find your attachment in your previous post. And, unless we reproduce the issue on our end, we cannot move forward to figure it out. So, kindly provide / paste your sample code (runnable) here. Also attach your output Excel file here, we will check it soon. Moreover, please give more details and screen shots to reproduce the issue on our end. This will help us really to trace the issue more precisely.

Thank you.

Hi,


We have evaluated your issue further.
Well, it is not the issue of our component but of the
precision of the number for Float object. You can just test the code like
following:
e.g
Sample code:

System.out.println(Float.valueOf(“0.04”).doubleValue());

Please use Double.valueOf(“0.04”) instead and then you can get the desired result.

Thank you.

Hi,


And, here is my complete (runnable) sample code for your reference for your needs:
e.g
Sample code:

//Main method:

Workbook workbook = null;
try
{
workbook = new Workbook();

} catch (Exception e) {

e.printStackTrace();

}

Style cellStyle = workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).getStyle();

cellStyle.setCustom(“0.00%”);

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).setStyle(cellStyle);

workbook.getWorksheets().get(0).getCells().getRows().get(0).get(0).putValue(getFloat(“4”));

try {

workbook.save(“out1.xlsm”);

} catch (Exception e) {

e.printStackTrace();

} finally {

System.out.println(“File Generated successfully!”);

}


private static Double getFloat(String string) {

Double returnValue = null;

returnValue = Double.valueOf(string) / 100;

return returnValue;

}


Thank you.