Hi, thank you for your suggestion, however, something is not working as expected here - the row height isn’t changing as you say, in fact, it remains in a fixed value regardless even when it is manually set in code.
here is the code snippet. adding a table with 5 rows, and setting the height to row 0 doesn’t change the height from 2560. adding text doesn’t also change that.
it is important to note that the output does show the row height it was set to be and not 2560, but the property table.GetRowHeight(0) always returns 2560.
Please advise.
private void Form1_Load(object sender, EventArgs e)
{
int fontIndex;
Presentation p = new Presentation();
System.Drawing.Font mainSlideFont = CreateAndAddFont(p, "arial", 10, out fontIndex, false, false);
Slide slide =
p.AddBodySlide();
string textToAdd = "some long text to place in a table";
Size size = GetNeededSizeForText(textToAdd, mainSlideFont);
Table table = slide.Shapes.AddTable(0, 0, size.Width, size.Height, 1, 4);
table.Height = 5 * size.Height;
TextFrame tf = table.GetCell(0, 0).TextFrame;
table.SetRowHeight(0, size.Height);
tf.Text = textToAdd;
foreach (Paragraph par in tf.Paragraphs)
{
par.HasBullet = false;
par.Alignment = TextAlignment.Left;
foreach (Portion por in par.Portions)
{
por.FontHeight = 10;
por.FontIndex = fontIndex;
}
}
// BUG - the height is not changing at all!
double cellHeight = table.GetCell(0, 0).Height;
p.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "1.ppt"), Aspose.Slides.Export.SaveFormat.Ppt);
}
// get the string measurement
private Size GetNeededSizeForText(string s, System.Drawing.Font font)
{
Size size = System.Windows.Forms.TextRenderer.MeasureText(s, font);
size = new Size(GetSlidePixels(size.Width), GetSlidePixels(size.Height));
return size;
}
private int GetSlidePixels(double screenPixels)
{
// 5760 / 922;
double ratio = 5760 / 922.0;
double value = ratio * screenPixels;
return (int)value;
}
private System.Drawing.Font CreateAndAddFont(Presentation presentation, string fontName, int fontSize, out int foundFontIndex,
bool isBold, bool isUnderline)
{
// Try to find the given font, if needed, adds it to the presentation fonts:
for (int fontIndex = 0; fontIndex < presentation.Fonts.Count; fontIndex++)
{
if (presentation.Fonts[fontIndex].FontName.Equals(fontName, StringComparison.OrdinalIgnoreCase))
{
foundFontIndex = fontIndex;
return new System.Drawing.Font(presentation.Fonts[fontIndex].FontName, fontSize);
}
}
FontEntity fntEntNew = new FontEntity(presentation, presentation.Fonts[0]);
fntEntNew.FontName = fontName;
foundFontIndex = presentation.Fonts.Add(fntEntNew);
FontEntity fontEntity = presentation.Fonts[foundFontIndex];
System.Drawing.FontStyle fontStyle = System.Drawing.FontStyle.Regular;
if (isBold && isUnderline)
fontStyle = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Underline;
else if (isBold)
fontStyle = System.Drawing.FontStyle.Bold;
else if (isUnderline)
fontStyle = System.Drawing.FontStyle.Underline;
System.Drawing.Font font = new System.Drawing.Font(
fontEntity.FontName, fontSize, fontStyle);
return font;
}