Aktualisieren Sie das ActiveX ComboBox Steuerelement mit Node.js via C++

Mögliche Verwendungsszenarien

Sie können die Werte des ActiveX-ComboBox-Steuerelements mit Aspose.Cells for Node.js via C++ lesen oder schreiben. Greifen Sie auf das ActiveX-Steuerelement über Shape.getActiveXControl() zu und prüfen Sie seinen Typ über ActiveXControlBase.getType(), es sollte den Wert ControlType.ComboBox zurückgeben, und wandeln Sie es dann in ein ComboBoxActiveXControl Objekt um, um seine Eigenschaften zu lesen oder zu modifizieren.

Bitte laden Sie die im folgenden Beispielcode verwendete Beispieldatei herunter.

Aktualisieren Sie das ActiveX-ComboBox-Steuerelement

Der folgende Screenshot zeigt die Auswirkung des Beispielcodes auf die Beispieldatei. Wie Sie sehen können, wurde der Wert der ActiveX-ComboBox auf “Dies ist die Kombinationsfeldsteuerung” aktualisiert.

todo:image_alt_text

Beispielcode

Der folgende Beispielcode aktualisiert den Wert des ActiveX-ComboBox-Steuerungselements, das sich in der Beispieldatei Excel befindet.

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "SourceFile_activex.xlsx");
// Create a workbook
const wb = new AsposeCells.Workbook(filePath);

// Access first shape from first worksheet
const shape = wb.getWorksheets().get(0).getShapes().get(0);

// Access ActiveX ComboBox Control and update its value
if (shape.getActiveXControl() != null)
{
// Access Shape ActiveX Control
const c = shape.getActiveXControl();

if (c instanceof AsposeCells.ComboBoxActiveXControl)
{
// Type cast ActiveXControl into ComboBoxActiveXControl and change its value
const comboBoxActiveX = new AsposeCells.ComboBoxActiveXControl(c);
comboBoxActiveX.setValue("This is combo box control with updated value.");

}

}

// Save the workbook
const outputFilePath = path.join(dataDir, "OutputFile_out.xlsx");
wb.save(outputFilePath);