How to position a table directly below some text

Hi,

I am evaluating the product Aspose.Slides.
I wish to place a table below some text called “LAST LINE”. How do you achieve this?

In the program below I use the setting:
ashp2.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;
in the second slide but it does not work but does work in the first slide, i.e. by setting:
ashp1.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;

The odd thing is that in PowerPoint under Format Shape/Text Box/Autofit the Resize shape to it text is selected but the Textframe is not resized to fit the text. Am I doing something wrong here as to me something seems inconsistent. I am also fairly new to this library.

However
Do you have any ideas? Thank you very much.

There are 2 functions FormatSlide() and SetPortionFont():

public static void FormatSlide()
{
using (Presentation pres = new Presentation())
{
//Instantiate SlideCollection class
ISlideCollection slds = pres.Slides;
ILayoutSlide layoutTitleAndObject = null;

for (int i = 0; i < pres.LayoutSlides.Count; i++)
{
layoutTitleAndObject = pres.LayoutSlides[i];
if (layoutTitleAndObject.LayoutType == SlideLayoutType.TitleAndObject)
{
slds[slds.Count - 1].LayoutSlide = layoutTitleAndObject;

pres.Slides.AddEmptySlide(layoutTitleAndObject);
}
}

// Add a slide
pres.Slides.AddEmptySlide(layoutTitleAndObject);

ISlide sld = pres.Slides[0];
IAutoShape ashp1 = (IAutoShape)sld.Shapes[0];
SetPortionFont(ashp1.TextFrame.Paragraphs[0].Portions[0], “Calibri”, NullableBool.False, 28, FillType.Solid, Color.Black);
ashp1.TextFrame.Paragraphs[0].Portions[0].Text = “FIRST SLIDE”;
ashp1.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
ashp1.TextFrame.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Left;
ashp1.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;

sld = pres.Slides[1];
ashp1 = (IAutoShape)sld.Shapes[0];
ashp1 = (IAutoShape)sld.Shapes[0];
SetPortionFont(ashp1.TextFrame.Paragraphs[0].Portions[0], “Calibri”, NullableBool.False, 28, FillType.Solid, Color.Black);
ashp1.TextFrame.Paragraphs[0].Portions[0].Text = “SECOND SLIDE”;
ashp1.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
ashp1.TextFrame.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Left;
ashp1.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;

// Main body of slide handling
IAutoShape ashp2 = (IAutoShape)sld.Shapes[1];
ashp2 = (IAutoShape)sld.Shapes[1];
SetPortionFont(ashp2.TextFrame.Paragraphs[0].Portions[0], “Calibri”, NullableBool.False, 24, FillType.Solid, Color.Black);
ashp2.TextFrame.Paragraphs[0].ParagraphFormat.Bullet.Type = BulletType.None;
ashp2.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
ashp2.TextFrame.Paragraphs[0].ParagraphFormat.Alignment = TextAlignment.Left;
// Slide text
ashp2.TextFrame.Paragraphs[0].Portions[0].Text = “SOME SUB TITLE” + “\n”;
ashp2.TextFrame.Paragraphs[0].Portions[0].Text += “SOME TEXT BELOW SUB TITLE” + “\n”;
ashp2.TextFrame.Paragraphs[0].Portions[0].Text += “LAST LINE”;
ashp2.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;

double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };

//Add table shape to slide
ITable tbl = sld.Shapes.AddTable(100, 50, dblCols, dblRows);

//Set border format for each cell
foreach (IRow row in tbl.Rows)
foreach (ICell cell in row)
{
cell.BorderTop.FillFormat.FillType = FillType.Gradient;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderTop.Width = 2;

cell.BorderBottom.FillFormat.FillType = FillType.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderBottom.Width = 2;

cell.BorderLeft.FillFormat.FillType = FillType.Pattern;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderLeft.Width = 2;

cell.BorderRight.FillFormat.FillType = FillType.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
cell.BorderRight.Width = 2;
}

//Merge cells 1 & 2 of row 1
tbl.MergeCells(tbl[0, 0], tbl[1, 0], false);

//Add text to the merged cell
tbl[0, 0].TextFrame.Text = “Merged Cells”;
pres.Save(“C:\dev\TEST.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);

}
}


public static void SetPortionFont(IPortion port, string sfont, NullableBool fontbold, float fontheight, FillType fill, Color fontcolor)
{
//Set the Font for the Portion
port.PortionFormat.LatinFont = new FontData(sfont);

//Set Bold property of the Font
port.PortionFormat.FontBold = fontbold;

//Set the Height of the Font
port.PortionFormat.FontHeight = fontheight;

//Set the color of the Font
port.PortionFormat.FillFormat.FillType = fill;
port.PortionFormat.FillFormat.SolidFillColor.Color = fontcolor;
}

Regards,
Anil

Hi Anil,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to request you to please share with us a sample presentation to explain your expected output. Please also narrow down the code while keeping focus over your requirements as I have not been able to understand your requirements completely. I will be able to proceed further once the requested information is shared by you.

Best Regards,

Hi Adnan,


Thanks for your email. I managed to fix my issue. It was easy to fix…it was a coding error from my side.

Regards,
Anil

Hi Anil,


Thank you for sharing your valuable feedback.

We are glad to hear that things have started working on your end. Please feel free to contact us if we can be of any help to you.

Best Regards,