Éviter la notation exponentielle des grands nombres lors de l importation à partir d un fichier HTML
Contents
[
Hide
]
Parfois, votre HTML contient des nombres comme 1234567890123456, qui font plus de 15 chiffres, et lorsque vous importez votre HTML dans un fichier Excel, ces nombres se convertissent en notation exponentielle comme 1.23457E+15. Si vous souhaitez que votre nombre soit importé tel quel et non converti en notation exponentielle, veuillez utiliser la propriété HtmlLoadOptions.getKeepPrecision() et la définir à true lors du chargement de votre HTML.
Le code d’exemple suivant explique l’utilisation de la propriété HtmlLoadOptions.getKeepPrecision(). L’API importera le nombre tel quel sans le convertir en notation exponentielle.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Sample Html containing large number with digits greater than 15
const html = "<html><body><p>1234567890123456</p></body></html>";
// Convert Html to byte array
const byteArray = new TextEncoder().encode(html);
// Set Html load options and keep precision true
const loadOptions = new AsposeCells.HtmlLoadOptions(AsposeCells.LoadFormat.Html);
loadOptions.setKeepPrecision(true);
// Convert byte array into stream
const stream = byteArray;
// Create workbook from stream with Html load options
const workbook = new AsposeCells.Workbook(stream, loadOptions);
// Access first worksheet
const sheet = workbook.getWorksheets().get(0);
// Auto fit the sheet columns
sheet.autoFitColumns();
// Save the workbook
const outputDir = path.join(__dirname, "output/");
workbook.save(path.join(outputDir, "outputAvoidExponentialNotationWhileImportingFromHtml.xlsx"), AsposeCells.SaveFormat.Xlsx);