Importa XML nel workbook Excel con JavaScript tramite C++
Contents
[
Hide
]
Aspose.Cells permette di importare la mappa XML all’interno della cartella di lavoro usando il metodo Workbook.importXml(string, string, number, number). Puoi importare la mappa XML con Microsoft Excel seguendo questi passaggi:
- Seleziona la scheda Sviluppo
- Fai clic su Importa nella sezione XML e segui i passaggi richiesti.
Dovrai fornire i tuoi dati XML per completare l’importazione. Ecco un esempio di dati XML che puoi utilizzare per i test.
Importa la mappa XML utilizzando Microsoft Excel
La seguente schermata mostra come importare la mappa XML utilizzando Microsoft Excel.
![]() |
|---|
Importa mappa XML usando Aspose.Cells for JavaScript tramite C++
Il seguente codice di esempio mostra come utilizzare Workbook.importXml(string, string, number, number). Genera il file Excel di output come mostrato in questa schermata.
![]() |
|---|
<!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>

