为工作簿指定自定义数字小数和组分隔符
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"); |