I want to have perpendicular arrow (indicating scale) in my chart.
I am able to draw a line but not able to bring it to the position i want.
The fail to understand what parameters need to be passed inorder to get it at the right position.
My code snippet is as below :
private void InsertScale(Aspose.Cells.Charts.Chart chart)
{
Aspose.Cells.Drawing.LineShape LineHorizontal = chart.Shapes.AddLine(25, 0, 1, 0, 10, 0);
LineHorizontal.X = 20;
LineHorizontal.Y = 200;
LineHorizontal.BeginArrowheadStyle = MsoArrowheadStyle.Arrow;
LineHorizontal.BeginArrowheadWidth = MsoArrowheadWidth.Wide;
LineHorizontal.EndArrowheadLength = MsoArrowheadLength.Long;
}
I am attaching a file to show what i am trying to achieve
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
You first need to create manually your desired Ms-Excel file with a line and arrows having your desired settings and position.
Then you will load it using Aspose.Cells inside a workbook and find out the parameters which you need to pass using debug and watches.
Hopefully, it will be helpful for you.
Hi,
I tried what you said by loading a template file and getting the properties,
But still it does not show the line in correct place,
one difference i noticed is that the type of the line when loaded by template is CellsDrawing type and i am using
Aspose.Cells.Drawing.LineShape LineHorizontal = chart.Shapes.AddLine(0, 572, 0, 30, 0, 51);
Hi,
To adjust the location of your line object inside a chart, please use its LeftInShape and TopInShape properties. You can set certain properties of the object to get it to where you want to adjust. See the following code for reference:
LineHorizontal.Placement = PlacementType.FreeFloating;
//Set the line.Height Property as per your needs
//Set the line.Width Property as per your needs
//Now set the left position of the line shape in the parent shape
line.LeftInShape = set the left indentation of your shape here;
//Now set the Top position of the line shape in the parent shape
line.TopInShape = set the top indentation of your shape here;
Hi,
Thanks for using Aspose.Cells.
It’s a complex and group shape, so it will take lot of efforts for you to rebuild it.
The easier way would be to import the groupshape from source xlsx file into a destination xlsx file.
Please see the following code, it imports all the shapes inside one workbook into another workbook.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\aspose.xlsx”;
//Workbook with your source shapes
Workbook workbook = new Workbook(filePath);
//Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Destination workbook where you want to copy shapes
Workbook wb = new Workbook();
//Access the first worksheet of destination workbook
Worksheet ws = wb.Worksheets[0];
//Import all shapes from source worksheet into destination worksheet
foreach (Shape shp in worksheet.Shapes)
{
Shape dstShape = ws.Shapes.AddCopy(shp, shp.UpperLeftRow, shp.Top, shp.UpperLeftColumn, shp.Left);
}
//Save the destination workbook.
wb.Save(“output.xlsx”);
thanks for the quick responses.
the issue is due to requirement i cant use a template.
I need to draw it by code
Hi,
In order to find the correct coordinate of your line shapes, first ungroup the shape, then set its alternative text.
After that search for your shape in worksheet.Shapes collection using Shape.AlternativeText property.
Once you find your shape, get its X, Y values and then you will be able to position your line shape correctly.
Hopefully, it will help you.
I somehow managed to draw the lines as i wanted.
What i am struggling with right now is the text on the line.
Code Snippet:
LineHorizontal.Text = “abc”;
LineHorizontal.IsTextWrapped = true;
LineHorizontal.Font.Size = 9;
LineHorizontal.TextHorizontalAlignment = TextAlignmentType.Top;
the text does not show up on first tr… when i click the line a couple of times it shows up and then gets invisible again.
Is there any property i am missing out on?
Also the vertical arrow as text at an angle.
what property will help me do that
Hi,
I would suggest that instead of adding text inside a line, you should add a textbox and reposition and rotate it using Shape.X,Y,RotationAngle properties.