Problem with Handling Height of a TableEx

Hi,

PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];

double[] widths = new double[1];
double[] heights = new double[2];

widths[1] = 660;
for (int j = 0; j < 2; j++) heights[j] = 21;

int index = slide.Shapes.AddTable(0, 0, widths, heights);
TableEx pptTable = (TableEx)slide.Shapes[index];

For(i = 0; i < 2; i++)
{
    CellEx pptCell = pptTable[0, i];
    PlaceText(pptCell);
}
Private Void PlaceText(CellEx pptCell)
{
    PresentationEx presen = new PresentationEx();
    SlideEx sampleSlide = pres.Slides[0];

    int index = sampleSlide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 1, 1, 100, 100);
    AutoShapeEx shpx = (AutoShapeEx)sampleSlide.Shapes[index];

    textFrame = shpx.TextFrame;
    textFrame.AnchoringType = TextAnchorTypeEx.Center;
    paragraph.ParagraphFormat.Alignment = TextAlignmentEx.Center;
    textFrame.Paragraphs[0].Portions[0].Text = "Sample - Text";
}

Whenever I use the above code, even when I declare the height as 21 or 2. I am getting the same height for each cell. Also I am not able to reduce the Table Height appearing in the PPTX(Manually).

Kindly let me know if i am wrong.

Thanks,
Koundinya P

Hi Koundinya,


I have tried to observe the sample code shared by you and there are some syntax issues in shared code. Also, when I execute the code I am not able to find any relevance with two sample code sections shared. I have modified the sample code and have generated the presentation.

public static void PlaceText(CellEx pptCell)

{

PresentationEx pres = new PresentationEx();
SlideEx sampleSlide = pres.Slides[0];
int index = sampleSlide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 1, 1, 100, 100);
AutoShapeEx shpx = (AutoShapeEx)sampleSlide.Shapes[index];
TextFrameEx textFrame = shpx.TextFrame;

textFrame.AnchoringType = TextAnchorTypeEx.Center;

ParagraphEx paragraph = textFrame.Paragraphs[0];
paragraph.ParagraphFormat.Alignment = TextAlignmentEx.Center;

textFrame.Paragraphs[0].Portions[0].Text = “Sample-Text”;

}
public static void TestIssue()
{
PresentationEx pres = new PresentationEx();

SlideEx slide = pres.Slides[0];

double[] widths = new double[1];
double[] heights = new double[2];
widths[0] = 660;
for (int j = 0; j < 2; j++)
heights[j] = 21;
int index = slide.Shapes.AddTable
(
0,
0,
widths,
heights
);

TableEx pptTable = (TableEx)slide.Shapes[index];

for(int i=0; i< 2; i++)

{

CellEx pptCell = pptTable[0,i];

PlaceText(pptCell);

}
pres.Save(“D:\Aspose Data\TestCellIssue.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);
}


In your sample code where you have called PlaceText(pptCell). In the definition of PlaceText(pptCell) there is no usage of CellEx. Can you please share the complete scenario and your requirements. Please also share the generated presentation on your end.

Many Thanks,

Hi Mudassir,

Can you check the output specifying height as 2.

I am getting same table height when i give height as 21 or 2. Table height is not decreasing even when i am changing the height.

Thanks,
Koundinya P

Hi Koundinya P,


I have observed the requirement shared by you and like to share that the minimum row height is dependent upon the font height set for the text in table row cell. You cannot set the row less than minimum row height. However, if you reduce the font height of cell the minimum row height will also get reduced. For your convenience, I have attached the modified sample code that will help you in understanding the concept.

public static void PlaceText(CellEx pptCell)
{
TextFrameEx textFrame = pptCell.TextFrame;
// textFrame.Paragraphs[0].Portions[0].Text = string.Empty;
textFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 1f;
textFrame.Paragraphs[0].Portions[0].Text = “Sample-Text”;

}
public static void TestIssue()
{
PresentationEx pres = new PresentationEx();

SlideEx slide = pres.Slides[0];

double[] widths = new double[1];
double[] heights = new double[2];

widths[0] = 660;
// widths[0] = 720;
for (int j = 0; j < 2; j++)
heights[j] = 2.0;

int index = slide.Shapes.AddTable(0,0,widths,heights);

TableEx pptTable = (TableEx)slide.Shapes[index];

for (int i = 0; i < 2; i++)
{

CellEx pptCell = pptTable[0, i];
PlaceText(pptCell);
}
pres.Save(“D:\Aspose Data\TestCellIssue.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);
}

Many Thanks,

Hi Mudassir,

When the CellHeight is 10, until a Font height of 5.0f the size of the table is as expected, Going beyond that is leading to increase in table height.

Is there any way to restrict the table height and assign a text havign Font Height of 9.0f in the Cell.

Kindly let me know asap

Thanks,

Koundi

Hi Koundi,


I have tried to understand the requirement shared by you. I have used the code snippet shared above and set the font height 9 in PlaceText() method. I have been able to generate the presentation with minimum cell height that will be sufficient to accommodate text with height 9. For your reference, I have shared the generated presentation.

Many Thanks,

Hi Mudassir,

I have analysed and found that the height discripancy is not due to the font i used but due to the

Internal Margins set in the shape. You can verify the below steps in the PPTX you have attached earlier.

Right Click the Cell of a table. Select FormatShape-->TextBox-->Internal Margins.

When i have set these margins to 0". I got the required table height.

Kindly let me know how i can manage these Internal Margins within the code.

Thanks,

Koundinya P

Hi Koundinya,


Thanks for your feedback. I will investigate in the mentioned area. However, I would request you to please share the sample presentation highlighting the issue along with the sample code that you have used to verify on your end. I will investigate it further to help you out.

Many Thanks,

Hi Mudassir,

The Issue can be identified in the TestCellIssue.pptx you have shared.
I am attaching the required files for your understanding.
TestCellIssueModifiedInternalMargins.pptx is the presentation for which the internal margins of the cells have been modified(Set to 0).
Kindly using the same code which you have provided and let us know how to handle the Internal Margins.


Thanks,
Koundinya P

Hi Koundinya P,


Please use the following sample code to set the margin values. I have also shared the generated presentation for your kind reference. Please share, if I may help you further in this regard.

public static void PlaceText(CellEx pptCell)
{
TextFrameEx textFrame = pptCell.TextFrame;
// textFrame.Paragraphs[0].Portions[0].Text = string.Empty;
textFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 9f;
textFrame.Paragraphs[0].Portions[0].Text = “Sample-Text”;

}
public static void TestIssue()
{
PresentationEx pres = new PresentationEx();

SlideEx slide = pres.Slides[0];

double[] widths = new double[1];
double[] heights = new double[2];

widths[0] = 660;
// widths[0] = 720;
for (int j = 0; j < 2; j++)
heights[j] = 2.0;

int index = slide.Shapes.AddTable(0, 0, widths, heights);

TableEx pptTable = (TableEx)slide.Shapes[index];

for (int i = 0; i < 2; i++)
{

CellEx pptCell = pptTable[0, i];
pptCell.MarginTop = 0.0;
pptCell.MarginBottom = 0.0;
pptCell.MarginLeft = 0.0;
pptCell.MarginRight = 0.0;
PlaceText(pptCell);
}
pres.Save(“D:\Aspose Data\TestCellIssue2.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);
}

Many Thanks,

Thanks a lot Mudassir.

This works fine as expected.

Thanks,

Koundinya P