Come aggiungere/inserire una casella di testo nel foglio di lavoro con JavaScript tramite C++

Aggiungere casella di testo al foglio di lavoro in Excel

Nel programma Excel (versione 07 e successive), ci sono due punti in cui puoi inserire caselle di testo. Uno in “inserisci-shapes”, l’altro sulla destra del menu superiore dell’opzione “Inserisci”.

metodo uno:

1

metodo due:

2

Come creare

Puoi creare caselle di testo con testo orizzontale o verticale.

  • Seleziona l’opzione corrispondente (orizzontale o verticale)
  • Fai clic sinistro sulla pagina
  • Tieni premuto il pulsante sinistro e trascina una distanza sulla pagina
  • Rilascia il pulsante sinistro

Ora hai una casella di testo.

Aggiungi la casella di testo al foglio di lavoro in Aspose.Cells for JavaScript tramite C++

Quando è necessario inserire automaticamente molte caselle di testo nel foglio di lavoro, il metodo di inserimento manuale è chiaramente un disastro. Se questo ti disturba, penso che questo documento ti sarà di aiuto. Aspose.Cells ti fornisce un’API per effettuare facilmente inserimenti di massa nel tuo codice.

Il seguente codice di esempio crea una casella di testo.

<!DOCTYPE html>
<html>
    <head>
        <title>Aspose.Cells Example - Add TextBox</title>
    </head>
    <body>
        <h1>Add TextBox to Workbook</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, Utils } = 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 a file is provided, open it; otherwise create a new workbook
            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 first worksheet from the collection
            const sheet = workbook.worksheets.get(0);

            // Add the TextBox to the worksheet
            sheet.textBoxes.add(6, 10, 100, 200);

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

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

Otterrai un file simile a file risultato. Nel file, vedrai quanto segue: