Añadir una referencia a la biblioteca en el proyecto VBA en el libro con JavaScript a través de C++
Contents
[
Hide
]
A veces, es necesario agregar o registrar la referencia de la biblioteca en el proyecto VBA a través del código. Puedes hacerlo usando el método VbaProjectReferenceCollection.addRegisteredReference(string, string) de Aspose.Cells.
Agrega una referencia de la biblioteca al proyecto VBA en Microsoft Excel
En Microsoft Excel, puedes agregar una referencia de la biblioteca al proyecto VBA haciendo clic en Herramientas > Referencias… manualmente.
** Añade una referencia a la biblioteca en el proyecto VBA en un libro usando Script Aspose.Cells for Java a través de C++**
El siguiente ejemplo de código añade o registra dos referencias de biblioteca en el proyecto VBA del libro de trabajo usando el método VbaProjectReferenceCollection.addRegisteredReference(string, string).
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells - Add VBA References Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.xlsm,.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 } = 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 () => {
// Creating a new Workbook
const workbook = new Workbook();
// Accessing the VBA project (converted from getVbaProject())
const vbaProj = workbook.vbaProject;
// Accessing References collection (converted from getReferences())
vbaProj.references.addRegisteredReference("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
vbaProj.references.addRegisteredReference("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library");
// Saving the workbook as XLSM and providing a download link
const outputData = workbook.save(SaveFormat.Xlsm);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'Output_out.xlsm';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Generated XLSM File';
document.getElementById('result').innerHTML = '<p style="color: green;">VBA references added and file generated. Click the download link to save the file.</p>';
});
</script>
</html>