为工作簿指定自定义数字小数点和分组分隔符
Contents
[
Hide
]
在Microsoft Excel中,您可以在“高级Excel选项”中指定自定义十进制和千位分隔符,而不是使用系统分隔符,如下面的屏幕截图所示。
Aspose.Cells提供WorkbookSettings.NumberDecimalSeparator和WorkbookSettings.NumberGroupSeparator属性,以设置数字的自定义分隔符进行格式化/解析。
使用Microsoft Excel指定自定义分隔符
下面的屏幕截图显示了“高级Excel选项”,并突出显示了指定“自定义分隔符”的部分。
使用Aspose.Cells指定自定义分隔符
下面的示例代码说明了如何使用Aspose.Cells API指定自定义分隔符。它将十进制和组分隔符分别指定为点和空格。
用于指定自定义数字小数点和分组分隔符的C#代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
Workbook workbook = new Workbook(); | |
// Specify custom separators | |
workbook.Settings.NumberDecimalSeparator = '.'; | |
workbook.Settings.NumberGroupSeparator = ' '; | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Set cell value | |
Cell cell = worksheet.Cells["A1"]; | |
cell.PutValue(123456.789); | |
// Set custom cell style | |
Style style = cell.GetStyle(); | |
style.Custom = "#,##0.000;[Red]#,##0.000"; | |
cell.SetStyle(style); | |
worksheet.AutoFitColumns(); | |
// Save workbook as pdf | |
workbook.Save(dataDir + "CustomSeparator_out.pdf"); |