Werte von verbundenen Formen mit JavaScript über C++ aktualisieren
Contents
[
Hide
]
Manchmal haben Sie in Ihrer Excel-Datei eine verknüpfte Form, die mit einer Zelle verbunden ist. In Microsoft Excel ändert sich der Wert der verknüpften Zelle, wenn Sie den Wert der verknüpften Form ändern. Dies funktioniert auch mit Aspose.Cells for JavaScript über C++, wenn Sie Ihre Arbeitsmappe im XLS- oder XLSX-Format speichern möchten. Wenn Sie Ihre Arbeitsmappe jedoch im PDF- oder HTML-Format speichern möchten, müssen Sie die ShapeCollection.updateSelectedValue()-Methode aufrufen, um den Wert der verknüpften Form zu aktualisieren.
Beispiel
Das folgende Screenshot zeigt die Quell-Excel-Datei, die im untenstehenden Beispielcode verwendet wird. Es enthält ein verbundenes Bild, das mit den Zellen A1 bis E4 verknüpft ist. Wir werden den Wert der Zelle B4 mit Aspose.Cells ändern und dann die ShapeCollection.updateSelectedValue()-Methode aufrufen, um den Wert des Bildes zu aktualisieren und als PDF zu speichern.

Sie können die Quell-Excel-Datei und das Ausgabepdf über die bereitgestellten Links herunterladen.
JavaScript-Code zum Aktualisieren der Werte verknüpfter Formen
<!DOCTYPE html>
<html>
<head>
<title>Refresh Value Of Linked Shapes Example</title>
</head>
<body>
<h1>Refresh Value Of Linked Shapes Example</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 } = 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('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Create workbook from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet
const worksheet = workbook.worksheets.get(0);
// Change the value of cell B4
const cell = worksheet.cells.get("B4");
cell.value = 100;
// Update the value of the Linked Picture which is linked to cell B4
worksheet.shapes.updateSelectedValue();
// Save the workbook in PDF format
const outputData = workbook.save(SaveFormat.Pdf);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'outputRefreshValueOfLinkedShapes.pdf';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download PDF File';
document.getElementById('result').innerHTML = '<p style="color: green;">Operation completed successfully! Click the download link to get the PDF.</p>';
});
</script>
</html>