To create a parallelogram shape in Excel using Aspose.Cells, you need to set the appropriate properties for the shape, including its dimensions and position. The goal is to ensure that the bottom-right and top-right points are aligned as shown in your reference image.
Solution
You can achieve this by using the AddShape method to create a parallelogram and then adjusting its properties such as position and size. Here’s how you can do it:
Code
Here’s a sample code snippet to create a parallelogram shape in an Excel worksheet:
using Aspose.Cells;
using Aspose.Cells.Drawing;
class Program
{
static void Main()
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Define the position and size of the parallelogram
int upperLeftRow = 5;
int upperLeftColumn = 2;
int lowerRightRow = 10;
int lowerRightColumn = 5;
// Add a parallelogram shape
Shape parallelogram = worksheet.Shapes.AddShape(ShapeType.Parallelogram, upperLeftRow, upperLeftColumn, lowerRightRow, lowerRightColumn);
// Set the fill color
parallelogram.FillFormat.FillType = FillType.Solid;
parallelogram.FillFormat.SolidFill.Color = System.Drawing.Color.Blue;
// Optionally, set the line format
parallelogram.LineFormat.IsVisible = true;
parallelogram.LineFormat.Color = System.Drawing.Color.Black;
parallelogram.LineFormat.Weight = 2;
// Save the workbook
workbook.Save("ParallelogramExample.xlsx");
}
}
Next Steps
Adjust the upperLeftRow, upperLeftColumn, lowerRightRow, and lowerRightColumn values to position the parallelogram as needed.
Customize the fill and line formats to match your design requirements.
Run the code to generate the Excel file and verify the shape’s appearance.
If you have any further questions or need additional assistance, feel free to ask!
@imparthgalani
Please refer to the following example code.
ShapePath shapePath = new ShapePath();
shapePath.MoveTo(15, 0);
shapePath.LineTo(230, 0);
shapePath.LineTo(230, 15);
shapePath.LineTo(0, 15);
shapePath.Close();
int w = 230, h = 15;//The width and height values are set to the image size represented by the ShapePath object you defined above.
Workbook workbook = new Workbook();
Shape shape = workbook.Worksheets[0].Shapes.AddFreeform(1, 0, 1, 0, h, w, new ShapePath[] { shapePath });
shape.Line.FillType = FillType.Solid;
shape.Line.SolidFill.Color = Color.FromArgb(255, 0, 0);
shape.Fill.FillType = FillType.Solid;
shape.Fill.SolidFill.Color = Color.FromArgb(255, 255, 204);
workbook.Save("out_net.xlsx", SaveFormat.Xlsx);
In addition, parallelogram shapes cannot be changed to the shape you need. If the shape you need differs from the standard shape, we strongly recommend using the AddFreeform method to add the shape.
@imparthgalani
Thank you for your feedback. You are welcome. I’m glad your issue has been resolved. If you have any questions, please feel free to contact us at any time.