Excelファイルに保存する有効桁数を指定する

可能な使用シナリオ

デフォルトでは、Aspose.CellsはExcelファイル内の倍精度値の17桁の有効桁数を保存しますが、MS-Excelは15桁の有効桁数のみを保存します。CellsHelper.SignificantDigits プロパティを使用して、Aspose.Cellsのデフォルトの動作を17桁の有効桁数から15桁の有効桁数に変更できます。

Excelファイルに保存する有効桁数を指定

以下のサンプルコードは、Excelファイル内の倍精度値を保存する際にAspose.Cellsに15桁の有効桁数を使用するよう指定しています。出力エクセルファイルをご確認ください。その拡張子を .zip に変更して解凍すると、Excelファイル内には15桁の有効桁数のみが保存されていることがわかります。以下のスクリーンショットは、CellsHelper.SignificantDigits プロパティの出力エクセルファイルへの影響を説明しています。

todo:image_alt_text

サンプルコード

// 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);
//By default, Aspose.Cells stores 17 significant digits unlike
//MS-Excel which stores only 15 significant digits
CellsHelper.SignificantDigits = 15;
//Create workbook
Workbook workbook = new Workbook();
//Access first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Access cell A1
Cell c = worksheet.Cells["A1"];
//Put double value, only 15 significant digits as specified by
//CellsHelper.SignificantDigits above will be stored in excel file just like MS-Excel does
c.PutValue(1234567890.123451711);
//Save the workbook
workbook.Save(dataDir + "out_SignificantDigits.xlsx");