Verwalten des Textfelds mit JavaScript über C++

Mögliche Verwendungsszenarien

Es gibt Szenarien, in denen Sie TextBox-Objekte innerhalb eines Excel-Arbeitsblatts hinzufügen, aktualisieren oder manipulieren müssen. Dies kann nützlich sein, um Anmerkungen, Leittexte oder andere ergänzende Informationen zur Datenpräsentation hinzuzufügen. Aspose.Cells for JavaScript über C++ bietet robuste Funktionen zur Verwaltung von TextBox in Excel-Dokumenten.

Verwaltung von TextBox mit Aspose.Cells for JavaScript über C++

Dieses Beispiel zeigt, wie Sie:

  1. Erstellen Sie eine neue Arbeitsmappe.
  2. Fügen Sie eine TextBox-Form hinzu.
  3. Ändern Sie die Eigenschaften der TextBox bei Bedarf.
<!DOCTYPE html>
<html>
    <head>
        <title>Aspose.Cells TextBox Example</title>
    </head>
    <body>
        <h1>TextBox 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, Color } = 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');
            let workbook;

            if (fileInput.files && fileInput.files.length) {
                const file = fileInput.files[0];
                const arrayBuffer = await file.arrayBuffer();
                workbook = new Workbook(new Uint8Array(arrayBuffer));
            } else {
                workbook = new Workbook();
            }

            // Access the first worksheet
            const worksheet = workbook.worksheets.get(0);

            // Adding a TextBox shape
            const textBox = worksheet.shapes.addTextBox(2, 2, 100, 100);

            // Set TextBox properties (converted getters/setters to properties)
            textBox.text = "This is a TextBox.";
            textBox.fontSize = 12;
            textBox.fillColor = Color.fromArgb(255, 255, 255); // White background

            // Save the workbook 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 = 'TextBoxExample.xlsx';
            downloadLink.style.display = 'block';
            downloadLink.textContent = 'Download Excel File';

            document.getElementById('result').innerHTML = '<p style="color: green;">Workbook created/modified successfully. Click the download link to get the file.</p>';
        });
    </script>
</html>

Dieser Code zeigt, wie man eine TextBox in einem Excel-Arbeitsblatt erstellt und konfiguriert, einschließlich Anpassung der Größe, Position und Formatierung nach Ihren Anforderungen.

Beachten Sie, dass die Interaktion mit TextBoxen je nach Anwendungsfall variieren kann. Weitere Methoden und Eigenschaften finden Sie in der Aspose.Cells for JavaScript-Dokumentation für C++.