Range.EntityValue scheint nach Abschluss der Funktion nicht bestehen zu bleibenJavaScript

Javascript-Forum
Guest
 Range.EntityValue scheint nach Abschluss der Funktion nicht bestehen zu bleiben

Post by Guest »

Ich arbeite an einem benutzerdefinierten Excel-Add-In und möchte entityValue ein Verhalten erstellen, das dem integrierten Aktiendatentyp ähnelt (und Dokumentation hier: https://github.com/officedev/office-add -In-Samples/Baum/Main/Proben/Excel-Data-Type-Explorer). Das EntityValue scheint jedoch nicht über die Funktion hinaus zu bestehen, in der sie erstellt wurde. Wenn ich also die Entitätsverzeichnisse lesen möchte, ist es nicht definiert. Manifest.xml (innerhalb des DesktopFormfactors): < /p>

Code: Select all

    
TestData









< /code>
Somit erfassen wir in dieser Stichprobe nur die Menge und den Preis für ein Produkt. Name (sagen wir "Hämmer") und führen Sie einen Befehl aus dem Band aus, der diese Zelle in eine Entität von testdata umwandelt: < /p>
async function createProductDataType(event) {
try {
await Excel.run(async (context) => {
// Get the currently selected cell.
const range = context.workbook.getSelectedRange();
range.load(["address", "values", "entityValue"]);
await context.sync();

console.log("Converting cell to Product Data Type...");

// Assume the user entered a product into the cell.
const productID = range.values[0][0];

console.log("Product ID: " + productID);

// Populate additional details for the product (just for testing)
const productData = {
prdID: productID,
quantity: 123,
price: 2.95,
};

console.log("productData:" + JSON.stringify(productData, null, 2));

// Just write the a version of productID to verify
range.values = [["product type: " + productID]];

console.log("Range Values: " + JSON.stringify(range.values, null, 2));

// Create an object that conforms to the Excel.EntityValue interface.
const productEntity = {
entityType: "TestData", // matches the type defined in the manifest.
prdID: productID, // A unique identifier for the entity instance.
data: productData, // The detailed data for the entity.
};

// Assign productEntity to the entityValue property of the cell.
range.entityValue = productEntity;

// Update the cell's format to indicate it’s been converted.
range.format.fill.color = "#88D3AF";

range.load(["entityValue", "entityValue/entityType"]);
await context.sync();

// Verify the data in the cell
console.log("Entity Value:" + JSON.stringify(range.entityValue, null, 2));
console.log("Cell type: " + range.entityValue.entityType);

await context.sync();
});
} catch (error) {
console.log("Error in product Data Type creation: " + error);
} finally {
// Notify the host that the command function is complete.
event.completed();
}
}
< /code>
ruft diese Funktion aus dem Band wie erwartet auf. Die Konsole wird wie folgt aktualisiert: < /p>
[Log] "Converting cell to Product Data Type..."
[Log] "Product ID: Hammers"
[Log] "productData:{\n  \"prdID\": \"Hammers\",\n  \"quantity\": 123,\n  \"price\": 2.95\n}"
[Log] "Range Values:[\n  [\n    \"product type: Hammers\"\n  ]\n]"
[Log] "Entity Value:{\n  \"entityType\": \"TestData\",\n  \"prdID\": \"Hammers\",\n  \"data\": {\n    \"prdID\": \"Hammers\",\n    \"quantity\": 123,\n    \"price\": 2.95\n  }\n}"
[Log] "Cell type: TestData"
< /code>
Bisher, also (irgendwie) gut. Wenn ich versuche, Daten aus einer anderen Zelle abzurufen (z. B.  = a2.quantity), wird ein Fehler #Field zurückgegeben! (Und es gab keine Änderung der Zelle, in der wir diesen Entitätsdatentyp mit einem kleinen Symbol erstellt haben. Daten: (Funktionsname irrelevant, dies ist nur der Code, der die Prüfung durchführt): < /p>
    // Get the currently selected cell.
const range = context.workbook.getSelectedRange();
range.load(["address", "values", "entityValue"]);
await context.sync();

console.log("Checking on entity data for cell from another function...");
console.log("Value of CELL: " + range.values[0][0]);
console.log("Entity Value CELL: " + JSON.stringify(range.entityValue, null, 2));
< /code>
Wenn ich mir das Konsolenprotokoll dafür ansehe, sehe ich hier: < /p>
[Log] "Checking on entity data for cell from another function..."
[Log] "Value of CELL: product type: Hammers"
[Log] "Entity Value CELL: undefined"
Es scheint also, dass der EntityValue/Typ nicht wirklich in die Zelle eingestellt wurde.
Was mache ich falsch? (Ausführen der neuesten Beta von Excel, und ich habe die Anforderungen für die Excelapi -Version auf 1.18 festgelegt).

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post