指定要存储在Excel文件中的有效数字位数
Contents
[
Hide
]
可能的使用场景
默认情况下,Aspose.Cells在电子表格中存储双精度值的17个有效数字,而Excel应用程序仅存储15个有效数字。您可以更改Aspose.Cells的默认行为,即您可以在使用CellsHelper.SignificantDigits属性时将有效数字位数从17更改为15。
指定要存储在Excel文件中的有效数字位数
以下示例代码强制Aspose.Cells在存储Excel文件中的双精度值时使用15个有效数字。请检查输出Excel文件。更改其扩展名为.zip并解压缩,您将会看到,该Excel文件中只存储了15个有效数字。以下屏幕截图解释了CellsHelper.SignificantDigits属性对输出Excel文件的影响。
示例代码
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-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"); |