Evitar la notación exponencial de números grandes al importar desde HTML
Contents
[
Hide
]
A veces, tu HTML contiene números como 1234567890123456, que son mayores a 15 dígitos, y cuando importas tu HTML a un archivo Excel, estos números se convierten a notación exponencial como 1.23457E+15. Si quieres que tu número se importe tal cual y no se convierta en notación exponencial, por favor, usa la propiedad HtmlLoadOptions.keepPrecision y configúrala a true al cargar tu HTML.
El siguiente código de ejemplo explica el uso de la propiedad HtmlLoadOptions.keepPrecision. La API importará el número tal cual sin convertirlo en notación exponencial.
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Example Title</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, HtmlLoadOptions, LoadFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
// 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 HtmlLoadOptions(LoadFormat.Html);
loadOptions.keepPrecision = true;
// Convert byte array into stream
const stream = byteArray;
// Create workbook from stream with Html load options
const workbook = new Workbook(stream, loadOptions);
// Access first worksheet
const sheet = workbook.worksheets.get(0);
// Auto fit the sheet columns
sheet.autoFitColumns();
// Save the workbook
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'outputAvoidExponentialNotationWhileImportingFromHtml.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Workbook created successfully. Click the download link to download the file.</p>';
});
</script>
</html>