Excelファイルに格納する有効数字を指定する
Contents
[
Hide
]
考えられる使用シナリオ
デフォルトでは、Aspose.Cells は有効数字 15 桁のみを格納する Excel アプリケーションとは異なり、スプレッドシートに double 値の有効数字 17 桁を格納します。この場合、Aspose.Cells のデフォルトの動作を変更できます。を使用しながら、有効桁数を 17 から 15 に変更できます。CellsHelper.SignificantDigits財産。
Excelファイルに格納する有効数字を指定する
次のサンプル コードは、Aspose.Cells が 15 桁の有効数字を使用するように強制し、Excel ファイル内に double 値を格納します。を確認してください出力エクセルファイル.拡張子を .zip に変更して解凍すると、Excel ファイル内に有効数字が 15 桁しか格納されていないことがわかります。次のスクリーンショットは、CellsHelper.SignificantDigits出力 Excel ファイルのプロパティ。
サンプルコード
This file contains hidden or 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SignificantDigits.class) + "CellsHelperClass/"; | |
//By default, Aspose.Cells stores 17 significant digits unlike | |
//MS-Excel which stores only 15 significant digits | |
CellsHelper.setSignificantDigits(15); | |
//Create workbook | |
Workbook workbook = new Workbook(); | |
//Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Access cell A1 | |
Cell c = worksheet.getCells().get("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"); |