指定要存储在 Excel 文件中的有效数字

可能的使用场景

默认情况下,Aspose.Cells 在电子表格中存储双精度值的 17 位有效数字,这与仅存储 15 位有效数字的 Excel 应用程序不同。对于这种情况,您可以更改 Aspose.Cells 的默认行为,即;您可以在使用时将有效位数从 17 更改为 15CellsHelper.SignificantDigits财产。

指定要存储在 Excel 文件中的有效数字

以下示例代码强制 Aspose.Cells 在 excel 文件中存储双精度值时使用 15 位有效数字。请检查输出excel文件.将其扩展名更改为 .zip 并解压缩,您将看到,excel 文件中仅存储了 15 位有效数字。下面截图说明效果CellsHelper.SignificantDigits输出 excel 文件的属性。

待办事项:图片_替代_文本

示例代码

// 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");