Apart from changing the size of a shape in DsExcel, you can also change the geometry of a shape and modify its appearance. This can be achieved by setting the adjustment values of shapes, such as AutoShapes or Connectors. It allows you to have more control over the shapes in order to create efficient flowcharts, dashboards and reports.
DsExcel provides the Adjustments property in the IShape interface to get a collection of adjustment values for the specified AutoShape or Connector.
The valid ranges of adjustent values for different adjustement types are described below:
Adjustment type | Valid values |
Linear (horizontal or vertical) |
Value 0.0 represents the left or top edge of the shape. Value 1.0 represents the right or bottom edge of the shape. For shapes such as connectors and callouts, the values 0.0 and 1.0 correspond to the rectangle defined by the starting and ending points of the connector or callout line. Values lesser than 0.0 and greater than 1.0 are also valid. The valid values for the adjustment correspond to the valid adjustments that can be made to shapes in Excel by extending the adjustment points. For example, if you can only pull an adjustment point half way across the shape in Excel, the maximum value for the corresponding adjustment will be 0.5. |
Radial | Value 1.0 represents the shape width. Hence, the maximum value for radial adjustment is 0.5, which is half way across the shape. |
Angle | Value is expressed in degrees. If you specify the value outside the range of 180 degree, it will be normalized to be within that range. |
In most cases, if a value exceeds the valid range, it is normalized to the closest valid value.
Refer to the following example code to adjust the dimensions of a shape in Excel:
C# |
Copy Code |
---|---|
public void AdjustmentPointForShape() { // Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.Worksheets[0]; // Add a right arrow callout IShape shape = worksheet.Shapes.AddShape(AutoShapeType.RightArrowCallout, 20, 20, 200, 100); IAdjustments adjustments = shape.Adjustments; // Get the count of adjustment values for shape int c = adjustments.Count; Console.WriteLine("Count of Adjustment Values: " + c.ToString()); // Set adjustment values for shapes adjustments[0] = 0.5;// arrow neck width adjustments[1] = 0.4;// arrow head width adjustments[2] = 0.5;// arrow head height adjustments[3] = 0.6;// text box width // Saving workbook to Xlsx workbook.Save(@"AdjustmentPointForShape.xlsx", SaveFileFormat.Xlsx); } |