Creating a User-defined Cell on a PageSheet doesn't work properly

Hello,
I am trying to set a User-defined Cell on a PageSheet.

I followed your instructions on the following page:
Working with User-defined cells

However, it only describes how to create a User-defined Cell on a Shape, not on a page.

So I tried it with the following code:

Diagram diagram = new Diagram();
Aspose.Diagram.Page newPage = new Aspose.Diagram.Page();
newPage.Name = "Property only Page";
diagram.Pages.Add(newPage);

Aspose.Diagram.User newUserProperty = new User();
newUserProperty.Name = "MyUserProp";
newUserProperty.Value.Val = "MyUserValue";
newPage.PageSheet.Users.Add(newUserProperty);

diagram.Save("c://PropertyByAsposeToVsdx.vsdx", SaveFileFormat.Vsdx);

If I display the name and the value, the data is also displayed correctly on the console.
But after I have saved the diagram as a vsdx file, only the name is displayed in Visio but no value.

Then I thought about whether the missing data type might also be responsible for this.
In the Prop class, you can set a data type with Prop.Type.Value.
But in contrast to the Prop class, I have not found a way to set a data type for the User class. How do I set the data type in for User?

Do you any idea how the value of the User-defined Cell is empty in Visio?

regards
Steven
AspoerUser.JPG (12,0 KB)

@sgruth

Cause

The issue you’re encountering with the User-defined Cell on a PageSheet not displaying its value in Visio after saving is likely due to the absence of a specified data type for the User object. Unlike the Prop class, which allows setting a data type, the User class does not have a direct method for this.

Solution

To ensure that the value is correctly displayed in Visio, you need to set the data type for the User-defined Cell. While the User class does not explicitly allow setting a type, you can ensure that the value is correctly formatted and recognized by Visio.

Here’s how you can modify your code:

  1. Ensure that the value you are setting is in a format that Visio can recognize.
  2. Check if there are any additional properties or methods in the User class that could help in setting the type indirectly.

Code

Here’s an updated version of your code that includes a check for the value format:

Diagram diagram = new Diagram();
Aspose.Diagram.Page newPage = new Aspose.Diagram.Page();
newPage.Name = "Property only Page";
diagram.Pages.Add(newPage);

Aspose.Diagram.User newUserProperty = new User();
newUserProperty.Name = "MyUserProp";
newUserProperty.Value.Val = "MyUserValue"; // Ensure this value is in a recognized format
newPage.PageSheet.Users.Add(newUserProperty);

diagram.Save("c://PropertyByAsposeToVsdx.vsdx", SaveFileFormat.Vsdx);

Next Steps

  1. Test the updated code to see if the value now appears in Visio.
  2. If the issue persists, consult the Visio documentation for any specific requirements regarding User-defined Cells.
  3. Explore the properties of the User class to identify any additional settings that can be applied.

Please implement these changes and let me know if you need further assistance!

I really appreciate it when I receive an answer to a question in the forum shortly afterwards.

But this answer is not very helpful. Apart from a comment, nothing in the reply has been changed from my original code.

I just want to be able to write and save a string in a user-defined cell on a page.

Is there a real solution besides an AI-generated answer?

@sgruth

Thanks for screenshot.
Please try this sample code to write a string in the user:

        Aspose.Diagram.User newUserProperty = new User();
        newUserProperty.Name = "MyUserProp";
        newUserProperty.Value.Val = "MyUserValue";
        newUserProperty.Value.Ufev.Unit = MeasureConst.STR; //set the value as string
        newPage.PageSheet.Users.Add(newUserProperty);

Thanks.

thanks alot, this works.

@sgruth
Thanks for following the suggested workaround and good know that your issue is sorted out now.
Should you have further queries or issue, feel free to write us back, we will assist you soon.