Importer XML dans un classeur Excel avec JavaScript via C++
Contents
[
Hide
]
Aspose.Cells vous permet d’importer la carte XML dans le classeur en utilisant la méthode Workbook.importXml(string, string, number, number). Vous pouvez importer la carte XML en utilisant Microsoft Excel avec les étapes suivantes :
- Sélectionnez l’onglet Développeur
- Cliquez sur Importer dans la section XML et suivez les étapes requises.
Vous devrez fournir vos données XML pour compléter l’importation. Voici un exemple de données XML que vous pouvez utiliser pour les tests.
Importer une carte XML en utilisant Microsoft Excel
La capture d’écran suivante montre comment importer une carte XML en utilisant Microsoft Excel
![]() |
|---|
Importer une cartographie XML en utilisant Aspose.Cells for JavaScript via C++
Le code exemple suivant montre comment utiliser Workbook.importXml(string, string, number, number). Il génère le fichier Excel de sortie comme indiqué dans cette capture d’écran.
![]() |
|---|
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - Import XML</title>
</head>
<body>
<h1>Import XML into Workbook Example</h1>
<input type="file" id="xmlInput" accept=".xml,.txt" />
<button id="runExample">Import XML and Save</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, Worksheet, Cell } = 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 () => {
const fileInput = document.getElementById('xmlInput');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an XML file.</p>';
return;
}
const file = fileInput.files[0];
const xmlText = await file.text();
// Create a workbook
const workbook = new Workbook();
// Import your XML Map data starting from cell A1 on Sheet1
workbook.importXml(xmlText, "Sheet1", 0, 0);
// Save workbook to XLSX and provide download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output_out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
resultDiv.innerHTML = '<p style="color: green;">XML imported and workbook saved. Click the download link to get the file.</p>';
});
</script>
</html>

