Applying comma style and increase or decrease decimals in Java

Hi,

I'm evaluating Aspose cells... I generated xl using Aspose... Its good and simple API to use.

1) When applying comma style( XL Header) its says "style 'Comma' not found", this happens to a cell selection or column selection.

2) Not able to increase / decrease decimal at column level, but i'm able to do at cell level... I have 6000 rows, business users can't do at cell level.

Regards

raj

Hi raj,

Thanks for considering Aspose.

Well, I am not very clear about your problem. Sure, you may set style formattings to the whole column / row. Could you elaborate your problem and give us some more details, Also, kindly give us your sample code which you are using to get your task done.

Thank you.

Hi,

I generated XL it looks good, numbers are formatted with comma... every thing looks good. After generating XL, we apply increase / decrease decimals... ( Number we generated are 10 decimal places, In XL we display with out decimals..... when we apply increase/ decrease decimals ... its shows exact numbers in XL... It work good, if i apply each cell level ).

I will give exampe,

1) Generate an XL.

2) Select a column( top row have column names A, B,C,D... XL column names)... which select a column which shows SUM of entire column.

2.1) After selecting column click on comma style from XL header (Symbols $, %, comma style and increase decrease decimal symbols)) its an image looks like " , " ... next to this image increase and decrease decimal ....

I'm attaching image... In my image I select column B...named as Amount. I marked header symbols with blue circle...

Regards

Raj

Hi,

Thanks for considering Aspose.

I created a sample code for your need. The following code apply a custom style (the style inserts the comma b/w numbers with two decimal places) to the whole column "B". Kindly consult it.

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Cell cell = cells["A1"];
cell.PutValue("Name");
cell.Style.ForegroundColor = Color.Yellow;
cell.Style.Pattern = BackgroundType.Solid;
cell = cells["A2"];
cell.PutValue("Raj");
cell = cells["A3"];
cell.PutValue("Raju");

cell = cells["B1"];
cell.PutValue("Amount");
cell.Style.ForegroundColor = Color.Yellow;
cell.Style.Pattern = BackgroundType.Solid;
cell = cells["B2"];
cell.PutValue(66778);
cell = cells["B3"];
cell.PutValue(1980);

Style commastyle = workbook.Styles[workbook.Styles.Add()];
commastyle.Custom = "_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"_);_(@_)";
StyleFlag flag = new StyleFlag();
flag.NumberFormat = true;

cells.Columns[1].ApplyStyle(commastyle, flag);
worksheet.AutoFitColumn(1);

workbook.Save("d:\\test\\cstyles.xls");

And attached the output file, you may check it (The column B is formatted with your required style.)

Thank you.

please can u send me sample using java API.

Hi,

Thanks for considering Aspose.

Here it is (java code) and attached is the output excel file.

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();

Cell cell = cells.getCell("A1");
cell.setValue("Name");
Style stl = cell.getStyle();
stl.setColor(Color.YELLOW);
stl.setPatternStyle(PatternType.SOLID);
cell.setStyle(stl);
cell = cells.getCell("A2");
cell.setValue("Raj");
cell = cells.getCell("A3");
cell.setValue("Raju");

cell = cells.getCell("B1");
cell.setValue("Amount");
cell.setStyle(stl);
cell = cells.getCell("B2");
cell.setValue(66778);
cell = cells.getCell("B3");
cell.setValue(1980);

Style commastyle = cells.getCell("A1").getStyle();
commastyle.setCustom("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"_);_(@_)");
StyleFlag flag = new StyleFlag();
flag.setNumberFormat(true);

cells.getColumns().getColumn(1).applyStyle(commastyle,flag);
worksheet.autoFitColumn(1);

workbook.save("d:\\test\\cstyles.xls");

Thank you.

Sorry guys though java API its not working as u expected... but other example u provided its looks good. Test the sample what u provided me.

Following styles not working :- "$" , " %" and "," . It poups a message.

Regards

Hi,

Thanks for considering Aspose.

Well, I think now I can understand your problem. Do you mean that you cannot apply "$" currency, "%" percent and "," Comma Styles to Aspose.Cells for java generated excel files. We found the problem in java version of Aspose.Cells and we will fix it soon.

Thank you.

Hi,

Please try this fix.

We have added some default named style for the workbook.

Good works... Its look great now.

Regards

Raj