Free Support Forum - aspose.com

Unable to get the RectangleF of a paragraph located in a cell of a table in slides


#1

Hello,

I am trying to get the RectangleF of a Paragraph in a cell of a table in slides, but when I get the paragraph located in the cell and I want to get the RectangleF using this code:
Rect = new RectangleF(paragraph.GetRect().X, paragraph.GetRect().Y, paragraph.GetRect().Width, paragraph.GetRect().Height);
I get the below exception:
Message = “Unable to cast object of type ‘Aspose.Slides.Cell’ to type ‘Aspose.Slides.GeometryShape’.”
I am using IParagraph interface to obtain the paragraph. Pls tell me what’s going on


#2

@Trickstar

Can you please share source file along with complete code snippet so that we may further investigate to help you out.


#3

Thanks for your swift reply,
Unfortunately, I can’t upload a file of pptx so I uploaded an Image instead
here is a sample code:
var presentation = new Presentation(file);
List paragraphsRect = new List();
foreach (var slide in presentation.Slides)
{
foreach (var shape in slide.Shapes)
{
if (shape is ITable)
{
foreach (IColumn column in ((ITable)shape).Columns)
foreach (ICell cell in column)
foreach (IParagraph paragraph in cell.TextFrame.Paragraphs)
paragraphsRect.Add(paragraph.GetRect());
}
}
}
result_0.png (11.8 KB)


#4

@Trickstar,

Can you please share source presentation file, This will help us to resolve issue as soon as possible. You can share source file via Dropbox as well.


#5

@Adnan.Ahmad Okay, Here is the link https://www.dropbox.com/s/5kt1k0ud25621ts/source.pptx?dl=0


#6

@Trickstar,

I have shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.

using (Presentation presentation = new Presentation(path+“Test.pptx”))
{
foreach (IShape shape in presentation.Slides[0].Shapes)
{
Table table = shape as Table;
if (table != null)
{
Cell tableCell = table.Rows[0][0] as Cell;
Console.WriteLine("Cell: "+ tableCell.TextFrame.Text);
RectangleF frameRect = new RectangleF(
(float)(table.X + tableCell.OffsetX),
(float)(table.Y + tableCell.OffsetY),
(float)(tableCell.Width),
(float)(tableCell.Height));
Console.WriteLine("Cell frame: " + frameRect);

                }
            }
      }

#7

@Adnan.Ahmad Thanks once again for your swift reply,
This is how to get the coordinates of the cell, I want to know if it is possible to get the paragraph and also the portion in the paragraph coordinates in that particular cell.


#8

@Trickstar,

I like to inform that we dont have function for instant getting of paragraphs/potions coordinates. You have to calculate it by yourself. If there is still an issue than please share requirements we will investigate further on our end to help you out.


#9

@Adnan.Ahmad Okay, thank you for your reply, One last question, is it possible to get the width of a portion in a paragraph?


#10

@Trickstar,

I regret to share that at present the support for getting the size of Portion or Paragraph inside TextFrame is not available in API. An issue with ID SLIDESNET-40977 has been created in our issue tracking system to provide the requested support. We will share the good news with you as soon as the issue will be fixed.