OpenXML, PresentationML Table height and line height when wrapping words

I am new to Open Xml and created a reporting application using the Open Xml SDK. It fills the data in the table, and when the height of the table exceeds the moving border, clone the slide and fill in the next data set in new slides and so on. Everything works fine, but when some lines have data that is wrapped in 2 lines, they cannot get to a new page in the exact place. It seems that Open Xml still returns the row height as well as the row height when there is one row of data. Is there any way to resolve this.

Here is a piece of code that executes pagination logic (CreateTextCell is a method that creates a text cell and returns):

var tbl = current.Slide.Descendants<A.Table>().First(); var tr = new A.TableRow(); tr.Height = 200000; tr.Append(CreateTextCell(product.Name)); tr.Append(CreateTextCell(product.ProductNumber)); tr.Append(CreateTextCell(product.Size)); tr.Append(CreateTextCell(String.Format("{0:00}", product.ListPrice))); tr.Append(CreateTextCell(product.SellStartDate.ToShortDateString())); tbl.Append(tr); totalHeight += tr.Height; if (totalHeight > pageBorder) overflow = true; 
+4
source share
2 answers

I had a very similar question and it was found that the table height is not updated when populating the table through the Open XML SDK. It is only updated when the presentation actually opens in Power Point. It clearly won't help you figure out your code when you need to split a table into a new slide, but if you try this answer , it might help.

+1
source

If you can assume that all of your columns are above a fixed width, except for the first column where product.Name used, and your font style is the same, then you can use the following method instead of checking the height table> border.

First open your presentation in PowerPoint and go to the slide with your spreadsheet. Enter the data for a fixed-width column. Then in the first column, enter "XXXX ...." until the line breaks. Count the number of characters before a line break. This number will be maxLengthBeforeBreak

Secondly, clear the line from the first step above and enter in a similar line that does not interrupt the line. Copy and paste this line down and fill the table in the slide until you get the maximum number of lines for the slide that looks attractive to the user. This number of rows will be maxTableRowsPerSlide

Now that you fill each slide with lines, count the number of lines that you insert in the rowCount variable. Insert rows until rowCount < maxTableRowsPerSlide , then start a new slide.

And for each row - if the length of product.Name is> maxLengthBeforeOverflow , you can increase rowCount by dividing the length of product.Name by maxLengthBeforeOverflow to get the number lines that this string wraps.

+1
source

Source: https://habr.com/ru/post/1399719/


All Articles