How can we set the border color of shapes in excel?
In the below code we are able to set the shape.Line.weight but not having any option to set the color
var shape = workbook.Worksheets[sheetId].Shapes[shapeIndex];
shape.Line.Weight = 1;
How can we set the border color of shapes in excel?
In the below code we are able to set the shape.Line.weight but not having any option to set the color
var shape = workbook.Worksheets[sheetId].Shapes[shapeIndex];
shape.Line.Weight = 1;
To set the border color of shapes in Excel using Aspose.Cells, you can utilize the Line
property of the shape object. In your case, you can set the Line.Color
property to specify the desired border color. Here’s how you can modify your existing code to include the border color setting:
var shape = workbook.Worksheets[sheetId].Shapes[shapeIndex];
shape.Line.Weight = 1; // Set the line weight
shape.Line.Color = Color.FromArgb(255, 0, 0); // Set the border color to red
In this example, the Color.FromArgb(255, 0, 0)
method is used to create a red color for the border. You can replace the RGB values with any other color you wish to use.
Make sure to include the necessary namespaces at the top of your file:
using System.Drawing; // For Color
using Aspose.Cells; // For Workbook and Shape
This should allow you to set both the weight and the color of the shape’s border effectively. If you have any further questions or need additional assistance, feel free to ask!
Sources:
[1]: SetBorder.cs
shape.Line.Color = Color.FromArgb(255, 0, 0);
It is giving error as “LineFormat” does not contain definition for “Color”. I am using Aspose.Cells 24.10.0
@nraj
Please try the following sample code and check the attachment. sample.zip (7.5 KB)
// Create workbook from sample file
Workbook workbook = new Workbook();
// Access first worksheet from the collection
Worksheet sheet = workbook.Worksheets[0];
// Add the rectangle to the worksheet
RectangleShape shape = sheet.Shapes.AddRectangle(2, 0, 2, 0, 100, 300);
shape.Line.Weight = 5;
shape.Line.SolidFill.Color = Color.Red;
//Save
workbook.Save(filePath + "sample.xlsx", SaveFormat.Xlsx);
Hope helps a bit.