Posted 26 March 2024, 1:40 pm EST
- Updated 26 March 2024, 4:18 pm EST
Thank you for the information.
Sorry for the unclear use case.
I’m developing a web application using TypeScript (& SpreadJS) on the front end and C# on the server side.
When accessing the application, the following method created in C# is called:
public ActionResult Index(string returnUrl) {
var context = GetContext();
//
// some processes
//
var userLangs = Request.UserLanguages;
CultureInfo userCultureInfo = userLangs != null && userLangs.Length > 0
? new CultureInfo(userLangs[0])
: CultureInfo.CurrentCulture;
context.Separator = new MyContext.SeparateCharacterContainer
{
CurrencyGroupSeparator = userCultureInfo.NumberFormat.CurrencyGroupSeparator,
CurrencyDecimalSeparator = userCultureInfo.NumberFormat.CurrencyDecimalSeparator,
NumberGroupSeparator = userCultureInfo.NumberFormat.NumberGroupSeparator,
NumberDecimalSeparator = userCultureInfo.NumberFormat.NumberDecimalSeparator,
PercentGroupSeparator = userCultureInfo.NumberFormat.PercentGroupSeparator,
PercentDecimalSeparator = userCultureInfo.NumberFormat.PercentDecimalSeparator,
ListSeparator = userCultureInfo.TextInfo.ListSeparator
};
//
// some processes
//
}
“context” is an object that holds settings and is common in the program.
In this process, separators are stored on the server side.
When the Spread screen is displayed, the method created in C# is called by the following TypeScript function:
protected loadSpreadData(lockCancel: boolean) {
var me = this;
me.myHttp.doPost('GetSpreadData', { bookDataId: me.id, lockCancel: lockCancel }, function (data) {
me.loadSpread(data);
});
}
The C# method looks like this:
[HttpPost]
public ActionResult GetSpreadData(decimal bookDataId, bool lockCancel) {
//
// some processes
//
Dictionary<string, object> dto = new Dictionary<string, object>();
var separator = new Dictionary<string, string>
{
{ "CurrencyGroup", context.Separator.CurrencyGroupSeparator },
{ "CurrencyDecimal", context.Separator.CurrencyDecimalSeparator },
{ "NumberGroup", context.Separator.NumberGroupSeparator },
{ "NumberDecimal", context.Separator.NumberDecimalSeparator },
{ "PercentGroup", context.Separator.PercentGroupSeparator },
{ "PercentDecimal", context.Separator.PercentDecimalSeparator },
{ "List", context.Separator.ListSeparator },
{ "UICurrencyGroup", context.UISeparator.CurrencyGroupSeparator },
{ "UICurrencyDecimal", context.UISeparator.CurrencyDecimalSeparator },
{ "UINumberGroup", context.UISeparator.NumberGroupSeparator },
{ "UINumberDecimal", context.UISeparator.NumberDecimalSeparator },
{ "UIPercentGroup", context.UISeparator.PercentGroupSeparator },
{ "UIPercentDecimal", context.UISeparator.PercentDecimalSeparator },
{ "UIList", context.UISeparator.ListSeparator }
};
dto["Separator"] = separator;
//
// some processes
//
return this.Json(dto);
}
With this method, separators stored on the server side are returned as a JsonResult.
The returned value is processed by the following function:
protected loadSpread(data: any) {
//
// some processes
//
// set separator to current culture
// "culture-nm" is current culture name
var cultureInfo = GC.Spread.Common.CultureManager.getCultureInfo(angular.element("#culture-nm").val());
var numberFormat: any = cultureInfo.NumberFormat;
// data.Separator contain separators I want to set
numberFormat.currencyGroupSeparator = data.Separator.CurrencyGroup;
numberFormat.currencyDecimalSeparator = data.Separator.CurrencyDecimal;
numberFormat.numberGroupSeparator = data.Separator.NumberGroup;
numberFormat.numberDecimalSeparator = data.Separator.NumberDecimal;
numberFormat.percentGroupSeparator = data.Separator.PercentGroup;
numberFormat.percentDecimalSeparator = data.Separator.PercentDecimal;
cultureInfo.NumberFormat = numberFormat;
// set edited culture
GC.Spread.Common.CultureManager.addCultureInfo("lo-cl", cultureInfo);
GC.Spread.Common.CultureManager.culture("lo-cl");
//
// some processes
//
}
In this “loadSpread” function, the returned value is used to set data in the Spread.
Before setting data in the Spread, I tried to change current culture separators using the above process.
Is this information sufficient?
Thank you.