Hi,
When using the following
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
serie.DataLabels.Number = 5; //Currency rounded to dollar
}
on charts is there any reason why the printed values don’t follow the regional settings / CultureInfo?
I have everything set to French - Canada so the expected format would be
10 000 $
Yet I always end up with
$10 000
I’ve tried forcing everything to Canadian French on both
CurrentThread.CurrentCulture
and
workbook.Settings.CultureInfo
Yet it still won’t work, from what I can see by saving the Excel workbook Number = 5 forces a specific custom format of “$# ##0;($# ##0)” on the DataLabel
Which doesn’t work, I would expect to use the “Currency” category with 0 decimals instead which would work, is there any other way to achieve that?
I also messed around with workbook.Settings.Region and workbook.Settings.LanguageCode which still wouldn’t produce the expected results, by the way the type for LanguageCode seems weird (public CountryCode LanguageCode … ) some countries have more than one official language, Canada being one of them I’m not sure how the LanguageCode should be used then, I’m not sure it’s relevant here but I figured I’d mention it in case it is.
Worst case scenario I’ll force the format with DataLabels.NumberFormat but I’d rather follow the regional settings if at all possible.
Note that doing the same thing on a Cell works as expected, so it’s really just the DataLabel that seems to be handled in a different fashion.
Thank you for your help
PS: Here is the code snippet I used, I also attached the expected results and a print screen of what I’m currently seeing
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(3084, true); //French - Canada
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
Workbook workbook = new Workbook();
workbook.Settings.CultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture;
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
Style s = worksheet.Cells[“A1”].GetStyle();
s.Number = 5;
worksheet.Cells[“A1”].SetStyle(s);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
serie.DataLabels.Number = 5; //Currency rounded to dollar
}
workbook.Save(“cultureIssue_FR_CA.xlsx”);
Hi Luc,
{
serie.DataLabels.ShowValue = true;
// serie.DataLabels.Number = 5; //Currency rounded to dollar
serie.DataLabels.NumberFormat = “# ##0_)$;(# ##0 $)”;
}
Hi,
I used “French - Canada” as an example as it’s one of the languages we use the most, but our application can be used in multiple languages and countries. In that context using the regional settings directly is preferable.
Using NumberFormat would force me provided specific formats for all of them which is not ideal.
It’s somewhat incoherent on your side that using the property number on a Cell with
Style s = worksheet.Cells[“A1”].GetStyle();
s.Number = 5;
worksheet.Cells[“A1”].SetStyle(s);
Works as expected but the same properly on another entity (DataLabels.Number) doesn’t
In the chart, the Y axis shows the values properly, it’s really just the DataLabel that doesn’t work as expected. It’s something you should probably improve in the future
Now as for my issue I guess I’m stuck providing all the different NumberFormat my application can use, not really what I was hoping for, but it’ll do for now.
Thank you
Hi Luc,
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
Workbook workbook = new Workbook();
workbook.Settings.CultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture;
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
Style s = worksheet.Cells[“A1”].GetStyle();
s.Number = 5;
worksheet.Cells[“A1”].SetStyle(s);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
// serie.DataLabels.Number = 5; //Currency rounded to dollar
}
workbook.Save(dir + “culture_FR_CA.xlsx”);
Hi,
It works in Excel
workbook.Save(“cultureIssue_FR_CA.xlsx”)
but not when doing
chart.ToImage(“cultureIssue_FR_CA.png”);
Which I’ll need, I didn’t expect both results to be different…
For now I worked around the issue by using CurrentCulture.NumberFormat.Currency* elements, I still need to make some adjustments but overall I should be able to get it working.
It seems that unless I force the format on the cells (Style.Custom) and
datalabels (DataLabels.NumberFormat) I can’t get the right format when
using chart.ToImage (even for the cases where it shows up properly in
Excel)
I’ve attached updated code as well as outputs, in the excel files I added a printscreen of what I’m seeing.
Hi Luc,
- CELLSNET-44892: Culture settings for Workbook does not take effect for Chart’s DataLabels using Chart.ToImage
The issues you have found earlier (filed as CELLSNET-44892) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
The issue as provided as been fixed (when explicitly providing the style on all cells) but there is still one more context where I get the same issue
If I just use workbook.DefaultStyle = style; instead I still have the same issue where the excel worksheet and the generated ToImage file don’t match, the Excel File is OK and shows the numbers in the right format, but the PNG file does not, they should be identical.
I can work around the issue by manually setting the format on all the cells of my worksheet so it’s not critical but it’s still a bug that should be fixed in my opinion
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(3084, true); //French - Canada
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
Console.WriteLine("Aspose Version Info: " + CellsHelper.GetVersion());
Workbook workbook = new Workbook();
workbook.Settings.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
}
Style style = workbook.CreateStyle();
style.Number = 5;
workbook.DefaultStyle = style;
chart.ToImage(“cultureIssue_FR_CA_Workbook.DefaultStyle.png”);
workbook.Save(“cultureIssue_FR_CA_Workbook.DefaultStyle.xlsx”);
EDIT:
Turns out that even setting the style on the cell doesn’t work completely either, the values displayed on the values axis are still problematic and I don’t think those can be set manually like the DataLabels
Note that I used Aspose.Cells 16.11.1.0 for these tests
I updated the test project with the lastest changes, for the most part I’d expect the result when using ToImage to be identical to what is shown in the Excel. All xlsx files are OK, the png images are not except for the first one “cultureIssue_FR_CA_01_WorkbookCultureInfoOnly.png”
Hi,
Thanks for your sample code and using Aspose.Cells.
We have tested this issue with the following sample code (which is same as yours) with the latest version:
Aspose.Cells for .NET v16.11.3 and found the issue. PNG image of the chart does not match with MS-Excel chart.
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
- CELLSNET-44926 - PNG image of the chart does not match with MS-Excel chart
I have also attached the output excel file and png chart image generated at my end for a reference.
C#
// workbook.Settings.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
Style style = workbook.CreateStyle();
style.Number = 5;
workbook.DefaultStyle = style;
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
}
chart.Calculate();
chart.ToImage(“cultureIssue_FR_CA_Workbook.DefaultStyle.png”);
workbook.Save(“cultureIssue_FR_CA_Workbook.DefaultStyle.xlsx”);
Hi,
Hi,
The issue is resolved for all the provided test cases except one,
I will use the other methods so for my uses the current version is sufficient
The remaining issue is when the following method is used to set the format
serie.DataLabels.Number = 5; //Currency rounded to dollar
I’ve attached the resulting files linked to this method as well of a printscreen of what I’m seeing in Excel
The .png image should match the prinscreen
If you want to reproduce the issue the regional settings of the computer should be set to French - Canada
Thank you
Hi,
Style style = workbook.CreateStyle();
style.Number = 5;
workbook.DefaultStyle = style;
int sheetIndex = workbook.Worksheets.Add();
Worksheet worksheet = workbook.Worksheets[sheetIndex];
worksheet.Cells[“A1”].PutValue(2000);
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.ColumnStacked, 10, 0, 20, 10);
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
chart.NSeries.Add(“A1”, true);
foreach (Aspose.Cells.Charts.Series serie in chart.NSeries)
{
serie.DataLabels.ShowValue = true;
}
chart.Calculate();
chart.ToImage(“cultureIssue_FR_CA_Workbook.DefaultStyle-sha.png”);
workbook.Save(“cultureIssue_FR_CA_Workbook.DefaultStyle-sha.xlsx”);
That is the issue (dollar sign on the work side, and the thousand separator should be a space instead of a comma)
serie.DataLabels.Number = 5; //Currency rounded to dollar,
Hi,
- CELLSNET-44941 - Culture settings are not applying on output chart image
The issues you have found earlier (filed as CELLSNET-44926) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
The issues you have found earlier (filed as CELLSNET-44941) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan