How to set RoundedRectangle corner radius?

@amjad.sahi, @Professionalize.Discourse, @John.He, @simon.zhao

image.png (44.1 KB)

Shape commentShape = worksheet.Shapes.AddAutoShape(AutoShapeType.RoundedRectangle, 0, 0, 0, 0, 0, 0);							
commentShape.Placement = PlacementType.MoveAndSize; //Set the placement type as the Shapes will move and resize with cells.
commentShape.X = 150; //Shape Top properties
commentShape.Y = 150; //Shape Left properties
commentShape.WidthPt = 100; // Shape Width
commentShape.HeightPt = 300; // Shape Height

@imparthgalani

Cause

To set the corner radius of a RoundedRectangle shape in Aspose.Cells, you need to use the RoundedRectangle property of the shape after it has been created. The default implementation does not expose a direct way to set the corner radius during the shape creation.

Solution

You can adjust the corner radius using the SetRoundedCorners method after creating the shape. Here’s how you can do it:

Code

// Create a RoundedRectangle shape
Shape commentShape = worksheet.Shapes.AddAutoShape(AutoShapeType.RoundedRectangle, 0, 0, 0, 0, 0, 0);
commentShape.Placement = PlacementType.MoveAndSize; // Set the placement type
commentShape.X = 150; // Shape Top properties
commentShape.Y = 150; // Shape Left properties
commentShape.WidthPt = 100; // Shape Width
commentShape.HeightPt = 300; // Shape Height

// Set the corner radius
commentShape.SetRoundedCorners(20); // Set the desired corner radius

In this example, replace 20 with the desired radius value for the corners.

Next Steps

Implement the above code in your project and adjust the corner radius value as needed to achieve the desired appearance. If you have any further questions or need additional assistance, please ask!

I hope this helps!

@amjad.sahi, @Professionalize.Discourse, @John.He, @simon.zhao

// Set the corner radius
commentShape.SetRoundedCorners(20); // Set the desired corner radius

This method will not exist in SetRoundedCorners(20) for the latest version

@imparthgalani
All adjustment points are adjusted in Shape.Geometry.ShapeAdjustValues. By default, there are no values in it, so they need to be added using Shape.Geometry.ShapeAdjustValues.Add(string, double) method. If there are any, the original values need to be overwritten. Only one adjustment point is adjusted based on the key value “adj”, and multiple adjustment values are adjusted using “adj1”, “adj2”… and so on. Here, the rounded rectangle only has one adjustment point, so add the “adj” parameter and value directly.

Please refer to the following example code to adjust the moving point.

Workbook wb = new Workbook();
Worksheet worksheet = wb.Worksheets[0];

Shape commentShape = worksheet.Shapes.AddAutoShape(AutoShapeType.RoundedRectangle, 0, 0, 0, 0, 0, 0);
commentShape.Placement = PlacementType.MoveAndSize; //Set the placement type as the Shapes will move and resize with cells.
commentShape.X = 150; //Shape Top properties
commentShape.Y = 150; //Shape Left properties
commentShape.WidthPt = 100; // Shape Width
commentShape.HeightPt = 300; // Shape Height

// adjust the moving point, Value needs to be less than 1
commentShape.Geometry.ShapeAdjustValues.Add("adj", 0.35);

wb.Save(filePath + "out_net.xlsx");

Hope helps a bit.

@John.He, Thanks for the right solution and quick answers.

In RoundedRectangularCallout shape, “adj3” value is set for the corner radius, is it ok ??

@imparthgalani
The RoundedRectangularCallout shape only has one adjustment point, so add the “adj” parameter and value directly.