We’re seeing sometimes inconsistent text wrapping in a table cell between Aspose and PowerPoint. A similar issue has been reported in this post: Text wrap does not match PowerPoint text wrap. Has this defect been fixed?
Hi Nan,
Thank you for the quick response. The aspose generated pptx file is the sample pptx file I attached to the original thread. As you can see in the sample file, the bar in the second column is perfectly placed on top of each cell except for the last row. Since the code is the same for rendering the bar, so the best theory we can come up with for the misplaced fourth bar is that in the first column of the third data row, Aspose renders it with only two lines (as opposed to three lines you saw being actually displayed in the powerpoint software), so in the Aspose code, the third row’s height is shorter than how it’s being rendered in PowerPoint. As a result, the bar in the fourth row is out of the alignment, because we use the combination of each table row’s height and table’s X value to calculate the X value for each bar graph. If you manually make the first column of the third data row two lines, you will see the bar in the fourth row will be placed perfectly in its cell. And this only happens if the powerpoint content is in non-English.
Hi Nan,
Here is the complete code that you can use to reproduce the issue.
Please modify the variable “filePath”'s value according to your own
environment.
using (Presentation pres = new Presentation())
{
var tableWidth = (float)691.2;
var fontSize = (float)8;
var headerData = new string[] { “Élément ou catégorie”, “ToptopTopTopTo 2020 : superposition de favorabilité”, “Différence entre TopTopTopTopTo 2020 et Norme de haute performance TestingValueV [TestingVale], score Favorable” };
var rowData = new List<string[]>
{
new []
{
“1. Les personnes avec travaille se montrent coopératives lorsqu’il s’agit d’accomplir le travail.”,
“92”, “14”
},
new []
{
“48. Je suis habilité(e) à prendre les mesures nécessaires pour répondre aux besoins des clients.”,
“59”, “30”
},
new [] {“49. Mon gestionnaire apprécie et reconnait ma contribution au travail.”, “75”, “N/A”}
};
var tableX = (float)111.168;
var tableY = (float)128.519928;
double[] rows = new double[] { 1 };
var baseColWidths = new double[] { (double)tableWidth / 100 * 30, (double)tableWidth / 100 * 20, (double)tableWidth / 100 * 22 };
ISlide sld = pres.Slides[0];
//Add table shape to slide
ITable tbl = sld.Shapes.AddTable(tableX, tableY, baseColWidths.ToArray(), rows);
var i = 0;
foreach (var header in headerData)
{
var cell = tbl.Rows[0][i];
var textFrame = cell.TextFrame;
textFrame.Paragraphs.Clear();
textFrame.Paragraphs.AddFromHtml(header);
cell.BorderBottom.FillFormat.FillType = FillType.Solid;
cell.BorderBottom.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderBottom.Width = 3.0;
cell.BorderTop.FillFormat.FillType = FillType.Solid;
cell.BorderTop.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderTop.Width = 3.0;
cell.BorderLeft.FillFormat.FillType = FillType.Solid;
cell.BorderLeft.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderLeft.Width = 3.0;
cell.BorderRight.FillFormat.FillType = FillType.Solid;
cell.BorderRight.FillFormat.SolidFillColor.Color = Color.Gray;
cell.BorderRight.Width = 3.0;<span style="color:#2b91af;">IParagraph</span> p = textFrame.Paragraphs[0]; p.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; p.ParagraphFormat.DefaultPortionFormat.FontHeight = fontSize; p.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.White; p.ParagraphFormat.Alignment = <span style="color:#2b91af;">TextAlignment</span>.Center; p.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>); i++; } <span style="color:blue;">var</span> rowIndex = 1; <span style="color:blue;">foreach</span> (<span style="color:blue;">var</span> row <span style="color:blue;">in</span> rowData) { i = 0; <span style="color:blue;">var</span> tblRow = tbl.Rows.AddClone(tbl.Rows[0], <span style="color:blue;">false</span>)[0]; <span style="color:blue;">foreach</span> (<span style="color:blue;">var</span> currentRowData <span style="color:blue;">in</span> row) { <span style="color:blue;">var</span> cell = tbl.Rows[rowIndex][i]; <span style="color:blue;">var</span> textFrame = cell.TextFrame; textFrame.Paragraphs.Clear(); <span style="color:blue;">if</span> (i == 1) { <span style="color:green;">//Add bar here</span> <span style="color:blue;">float</span> horizontalPadding = 7f; <span style="color:blue;">float</span> verticalPadding = 5f; <span style="color:blue;">int</span> height = 12; <span style="color:blue;">var</span> width = (<span style="color:blue;">float</span>)cell.Width - (2 * horizontalPadding); <span style="color:blue;">var</span> x = (<span style="color:blue;">float</span>)(cell.OffsetX + cell.Table.X); <span style="color:blue;">var</span> y = (<span style="color:blue;">float</span>)(cell.OffsetY + cell.Table.Y); <span style="color:#2b91af;">Func</span><<span style="color:blue;">double</span>, <span style="color:blue;">float</span>> calculateWidth = val => (width / 100) * (<span style="color:blue;">float</span>)val; <span style="color:blue;">var</span> rectX = x + horizontalPadding; <span style="color:blue;">var</span> currentRect = sld.Shapes.AddAutoShape(<span style="color:#2b91af;">ShapeType</span>.Rectangle, rectX, y + verticalPadding, calculateWidth(<span style="color:#2b91af;">Double</span>.Parse(currentRowData)), height); currentRect.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; <span style="color:#2b91af;">Color</span> foreColor = <span style="color:#2b91af;">Color</span>.Black; <span style="color:#2b91af;">Color</span> backgroundColor = <span style="color:#2b91af;">Color</span>.Green; currentRect.FillFormat.SolidFillColor.Color = backgroundColor; currentRect.LineFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.NoFill; currentRect.LineFormat.Width = 0; <span style="color:blue;">var</span> valueTextFrame = currentRect.AddTextFrame(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">"</span><span style="color:mediumseagreen;">{0:F0}</span><span style="color:#a31515;">%"</span>, <span style="color:#2b91af;">Double</span>.Parse(currentRowData))); valueTextFrame.TextFrameFormat.CenterText = <span style="color:#2b91af;">NullableBool</span>.True; valueTextFrame.OnEachPortion(portion => { <span style="color:blue;">var</span> portionFormat = portion.PortionFormat; portionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; portionFormat.FillFormat.SolidFillColor.Color = foreColor; portionFormat.FontHeight = fontSize; }); valueTextFrame.OnEachParagraph(para => { para.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>); }); } <span style="color:blue;">else</span> { textFrame.Paragraphs.AddFromHtml(currentRowData); cell.BorderBottom.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; cell.BorderBottom.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray; cell.BorderBottom.Width = 3.0; cell.BorderTop.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; cell.BorderTop.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray; cell.BorderTop.Width = 3.0; cell.BorderLeft.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; cell.BorderLeft.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray; cell.BorderLeft.Width = 3.0; cell.BorderRight.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; cell.BorderRight.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Gray; cell.BorderRight.Width = 3.0; <span style="color:#2b91af;">IParagraph</span> p = textFrame.Paragraphs[0]; p.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = <span style="color:#2b91af;">FillType</span>.Solid; p.ParagraphFormat.DefaultPortionFormat.FontHeight = fontSize; p.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = <span style="color:#2b91af;">Color</span>.Black; p.ParagraphFormat.Alignment = <span style="color:#2b91af;">TextAlignment</span>.Left; textFrame.TextFrameFormat.AnchoringType = <span style="color:#2b91af;">TextAnchorType</span>.Top; textFrame.OnEachParagraph( paragraph => { paragraph.ParagraphFormat.MarginLeft = 15F; }); p.ParagraphFormat.DefaultPortionFormat.LatinFont = <span style="color:blue;">new</span> <span style="color:#2b91af;">FontData</span>(<span style="color:#a31515;">"Segoe UI"</span>); } i++; } rowIndex++; } <span style="color:green;">//Write PPTX to Disk</span> <span style="color:blue;">string</span> filePath = <span style="color:#a31515;">@"Your file path goes here..."</span>; <span style="color:#2b91af;">Guid</span> guid = <span style="color:#2b91af;">Guid</span>.NewGuid(); pres.Save(filePath + <span style="color:#a31515;">"table_"</span> + guid.ToString() +"<span style="color:#a31515;">.pptx"</span>, <span style="color:#2b91af;">SaveFormat</span>.Pptx); }</pre>
Hi Nan,
The code is written in the project where the target framework is .Net 4.5. And the Aspose.Slide’s version is 14.8.
Hi Nan,
The latest Aspose.Slide.dll (16.12) didn’t fix the issue. Can you try reproducing the problem using the code I provided and look into it?