问题描述
我正在尝试使用.Net spreadsheetgear dll本地化excel单元格值,当我尝试生成excel时,我将portugese数字格式称为[= 0] 0; ###。###,00它应该显示为2.265,65的值,但是这并没有发生,它显示为2,265.65(。没有被替换为,为葡萄牙语)请帮助我有什么限制在excel或我们需要应用任何其他数字格式感谢
Sudha
p>通过在创建或打开一个特定的 CultureInfo
类型时,可以控制工作簿的某些本地化方面,例如货币,日期以及数字组和小数分隔符SpreadsheetGear中的工作簿文件。 (...)和(...)方法被重载以接受这个 CultureInfo
对象。如果您没有指定 CultureInfo
对象,则SpreadsheetGear默认为en-US。
我的猜测是,您的工作簿集目前正在使用en-US,因为您没有指定葡萄牙语 CultureInfo
类型。以下是一个示例,它应该演示如何使用上述 NumberFormat
按SpreadsheetGear的预期显示:
//创建一个指定pt-BR的新工作簿CultureInfo
IWorkbook工作簿= Factory.GetWorkbook(CultureInfo.GetCultureInfo(pt-BR));
IWorksheet工作表= workbook.ActiveWorksheet;
IRange cells = worksheet.Cells;
cells [A1]。NumberFormat =[= 0] 0; ###。###,00;
cells [A1]。值= 2265.65;
Console.WriteLine(cells [A1]。Text);
//输出:2.265,65
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
ThanksSudha
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
这篇关于使用spreadsheetgear(.Net)为Excel单元格定位值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!