HI,
I need to formatt a currency that comes in like ($564.90), which indiates a negative value. I am using this code to formatt it for the same
string a = "($564.90)";
string b = a.Substring(2);
double c = double.Parse(b.Substring(0, b.Length - 1));
cells[startRow + 2, 5].PutValue(b);
//cells[startRow + 2, 5].Style.Number = 14;
cells[startRow + 2, 5].Style.Custom = "_($* #,##0.00_);_($* (#,##0.00);_($* \" - \"??_);_(@_)";
but in the excel i get it as 564.90) ... I think the formatt for the custom style is not correct . I tried using all the 4 formats available in excel for this purpose and still ge the same output.Could you please help me out wiht this? I need it to be displayed as ($564.90)
Rgds
Soumya
Please try:
cells[startRow + 2, 5].Style.Custom = "$#,##0.00_);($#,##0.00)";
I have used the formatt that you have given, it still formatts like this 564.90) . The Opening braces and the $ sign are missing
I use the following code to set the format and it works fine. Attached is output file.
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
cells["A1"].PutValue(-546.9);
cells["a1"].Style.Custom = "$#,##0.00_);($#,##0.00)";
workbook.Save("d:\\test\\abc.xls");
Thnks, its fine now ... it was some inoout string format error.
NOw i have a problem wiht % ... sorry I am bumping into too many problems with these... My data is a double and i must show as % so i used the format '0.00%' ...
double d = double.Parse("567.89");
cells[startRow + 2, 5].Style.Number = 10;
//cells[startRow + 2, 5].Style.Custom = "0.00%";
cells[startRow + 2, 5].PutValue(d);
i get the data like 56789.00% , please help me with this one ... I must show it as 567.89%
56789.00% is correct.
567.89 = 56789.00%, not 567.89%.
Hi, is it possible to have a style print negative value in brackets and red color font?
Eg, ($1,000.00)
Matt
Hi,
Yes, quite possible. See the sample code below for your reference:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Aspose.Cells.Cell cell = cells[“A1”];
cell.PutValue(-1000);
Style currstyle = cell.GetStyle();
currstyle.Custom = “$#,##0.00_);Red”;
cell.SetStyle(currstyle);
worksheet.AutoFitColumn(0);
workbook.Save(“e:\test2\currstyles.xls”);
For complete reference, see the document:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-display-formats-of-numbers-dates.html
Thank you.