指定要存储在Excel文件中的有效数字
Contents
[
Hide
]
可能的使用场景
默认情况下,Aspose.Cells在Excel文件中存储双精度值的17个有效数字,而MS-Excel仅存储15个有效数字。您可以使用CellsHelper.SignificantDigits属性将Aspose.Cells的默认行为从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-.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"); |