指定要存储在 Excel 文件中的有效数字
Contents
[
Hide
]
可能的使用场景
默认情况下,Aspose.Cells 在 excel 文件中存储双精度值的 17 位有效数字,这与 MS-Excel 仅存储 15 位有效数字不同。您可以使用以下方法将 Aspose.Cells 的默认行为从 17 位有效数字更改为 15 位有效数字CellsHelper.SignificantDigits财产。
指定要存储在 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-.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"); |