Hi,
var workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Aspose.Cells.Cell cell = cells[“A1”];
cell.PutValue(2);
Style style = cell.GetStyle();
style.Custom = “[$-1010409]”$"#’##0;("$"#’##0)";
cell.SetStyle(style);
workbook.Save(“e:\test2\outputcustomformatting1.xlsx”);
Hi,
Thanks for your quick response. But unfortunately you have missed my point. The excel that you have uploaded; I can still see the backslash before single quote in the format cells option.
Please try with some bigger value like (1234567) and with the value 0. This will tell you the difference. For example please look into my uploaded file.
My requirement is, the values must be displayed as (For the negative values the first brackets are there) –
$276’258
$14’175’536
($5’882’471)
($176’497’086)
($64’707’176)
($14’175’536)
$5’882’471
$176’474’116
$64’707’176
Thanks,
Dipankar
Hi,
Hi,
Here is a catch. I can see only difference here that is I am using Excel 2003 and you are using Excel 2007 (probably).
Thanks,
Dipankar
Hi,
Another point the value 1234567 should be displayed as $1'234'567
Thanks,
Dipankar
Hi,
I have attached an excel file with the custom format that I want. Please consider that the file extention is XLS and I am using Excel 2003.
It is not possible to change the excel version at the organization level.
Thanks,
Dipankar
Hi,
Please find the attached image for your referrence.
Thanks,
Dipankar
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
We have opened your source file into MS-Excel 2003 and checked the cell format. We found there is no single quote in the cell custom format. Please see the attached image for your reference.
Hi,
Sorry. You have not got my point at all. The source file that I uploaded is just for your referrence which I want as final output. Just tell me how I can add that custom format in Aspose?
The actual issue is when I am trying to add the same format in Aspose and trying to export in excel, there I can see a "\" character before the single quote.
Thanks,
Dipankar
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
We loaded your source file i.e Report Custom Format.xls using the latest version: Aspose.Cells
for .NET v7.5.1.2 and observed the custom format value in debugging and wrote the following code. It works fine.
Please see the following screenshot for a reference.
C#
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cell cell = worksheet.Cells[“B1”];
Style style = cell.GetStyle();
style.Custom = “[$-1010409]"$"#,##0;\("$"#,##0\)”;
cell.SetStyle(style);
workbook.Save(“Output.xls”, SaveFormat.Excel97To2003);
Screenshot:
Hi,
But this is not what I want. The format will be same as you shown in the example. But I want single quote instead of comma.
Thanks,
Dipankar
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
Please provide us your desired custom format with single quote in MS-Excel file which you can create manually and post it here. We will look into your issue and help you asap.
Hi,
Sorry for the late reply. Please find the attached excel which is created on 2003. This is the exact output which I want.
Thanks & regards,
Dipankar Haldar
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
We have looked into your issue and opened your expected output sample file in MS-Excel 2003, we found, it is using comma instead of single quote.
We have created a screenshot for your reference.
Screenshot:
Hi,
I think you are not using the right attachment.
Please find the attachment here.
Thanks,
Dipankar
Hi,
Thanks for your posting and using Aspose.Cells.
We have again opened your attachment in MS-Excel 2003 and it still shows the same result. The custom formatting is using comma instead of single quote.
Could you provide screenshot of the file at your end?
Hi,
Please find the attached screenshot for your referrence.
Thanks,
Dipankar
Hi,
Thanks for your screenshot and using Aspose.Cells.
By your screenshot we finally found the difference was caused by the different locale. In your default locale the group separator should be single quote instead of ‘,’. When applying custom format to cell’s style, the Style.Custom uses standard separators such as ‘.’ for decimal separator and ‘,’ for group separator. When formatting the cell values, the standard separator will be replaced with the separator of specified locale used by the workbook. So, excel generated by code like Style.Custom=”#,##0” will format the cell value as “1’234’567” too as you expected in your default locale. For your sample.xls, to generate such an excel file by aspose.cells, such as cell “A3”, you code should be like following:
Cell cell = cells[“A3”];
Style style = cell.GetStyle();
style.Custom = “”$"#,##0;("$"#,##0)";
cell.SetStyle(style);
…