Question

I'm new to Open Xml, and have created a reporting application using Open Xml SDK. It populates the data in to a table, and when the table height exceeds slide border clone the slide and and populate the next set of data in new slides and so on. All works fine but when some of the rows have data that wraps to 2 lines fails to break in to new page at the exact place. Seems the reason is the Open Xml still returns the row height as same as the row height when there is single line of data. Is there anyway of resolving this.

Here is the a piece of code that does the pagination logic (CreateTextCell is a method that creates the text cell and return):

  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;
Was it helpful?

Solution

I had a very similar question and discovered that the height of the table is not updated when populating the table via Open XML SDK. It is only updated when the presentation is actually opened in Power Point. This obviously won't help you figure out in your code when to split the table to a new slide, but if you try this answer it might help.

OTHER TIPS

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

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

Second, clear the row from the first step above and enter in a similar row that doesn't line break. Copy and paste this row down and fill your table in the slide until you have the maximum number of rows for the slide that looks appealing to the user. This number of rows will be maxTableRowsPerSlide

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top