Localizing value for Excel cell using spreadsheetgear (.Net)

爱⌒轻易说出口 提交于 2020-01-06 13:52:13

问题


I am trying to localize the excel cell value using .Net spreadsheetgear dll, When i try to generate the excel i am suing the portugese number format as "[=0]0;###.###,00" which should display the value as 2.265,65 , but this is not happening and it is displaying as 2,265.65( "." is not getting replaced with "," for portugese), Please help me is there any limitations in the excel or do we need to apply anyother number format

Thanks Sudha


回答1:


You can control some localization aspects of a workbook such as currency, dates as well as the number group and decimal separators, by passing a particular CultureInfo type when creating or opening a workbook file in SpreadsheetGear. The Factory.GetWorkbook(...) and Factory.GetWorkbookSet(...) methods are overloaded to accept this CultureInfo object. If you do not specify a CultureInfo object, SpreadsheetGear defaults to "en-US".

My guess is that your workbook set is currently using "en-US" because you did not specify a Portugese CultureInfo type. Below is an example that should demonstrate how to get your above NumberFormat to appear as expected with SpreadsheetGear:

// Create a new workbook specifying "pt-BR" CultureInfo
IWorkbook workbook = Factory.GetWorkbook(CultureInfo.GetCultureInfo("pt-BR"));
IWorksheet worksheet = workbook.ActiveWorksheet;
IRange cells = worksheet.Cells;
cells["A1"].NumberFormat = "[=0]0;###.###,00";
cells["A1"].Value = 2265.65;
Console.WriteLine(cells["A1"].Text);
// Output: 2.265,65


来源:https://stackoverflow.com/questions/26292451/localizing-value-for-excel-cell-using-spreadsheetgear-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!