ブックでのカスタム番号の小数点とグループの区切り記号を指定する
Microsoft Excelでは、その他のExcelオプション から 詳細設定 を使用せずに、カスタムの小数点および千の区切り記号を指定できます。次のスクリーンショットでは、その手順が示されています。
Aspose.Cellsは、数値のフォーマット/解析のためにカスタムセパレータを設定するためのWorkbookSettings.NumberDecimalSeparatorとWorkbookSettings.NumberGroupSeparatorプロパティを提供します。
Microsoft Excelを使用してカスタムセパレータを指定する
次のスクリーンショットは、詳細設定 タブを示し、カスタムセパレータ を指定するセクションを強調しています。
Aspose.Cellsを使用してカスタムセパレータを指定する
次のサンプルコードは、Aspose.Cells APIを使用してカスタムセパレータを指定する方法を示しています。これにより、カスタム数値の10進セパレータとグループセパレータを、それぞれドットとスペースに設定します。
C#コードでカスタム数値の10進セパレータとグループセパレータを指定
// 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"); |