0

Is there a way to count the number of lines (I just need to determine the amount of space left) remaining in a page (Word File) using OpenXML and C#?

Edit:

My Pseudo-code for where I need to use this goes like this:

  1. Create array for table creation
  2. Open document
  3. Set table properties
  4. Cycle through the array using a for loop to create the cells and rows

    before one loop ends I want to check how much space is left on the page

  5. Append the table to the document

Here is the code for the loop:

for (var i = 0; i <= data.GetUpperBound(0); i++)
{
    var tr = new TableRow();
    for (var j = 0; j <= data.GetUpperBound(1); j++)
    {
        var tc = new TableCell();
        tc.Append(new Paragraph(new Run(new Text(data[i, j]))));

        // Assume you want columns that are automatically sized.
        tc.Append(new TableCellProperties(
            new TableCellWidth { Type = TableWidthUnitValues.Auto }));

        tr.Append(tc);

    }
    table.Append(tr);

    //Check for remaining space here
}
FortyTwo
  • 2,414
  • 3
  • 22
  • 33
Michael
  • 5
  • 6
  • what do your mean by remaining space? – Daniel A. White Mar 08 '18 at 21:25
  • You ask about *lines* yet your code seems to be about *rows*. Which is it? – kjhughes Mar 08 '18 at 21:31
  • I meant, how many lines of text would it take before it overflows to the next page. I need text to appear after the table. Actually, I just realized, the code should append the table to the document before checking for the remaining lines or space. – Michael Mar 08 '18 at 21:41
  • 1
    Unfortunately, you cannot know where a page will break at the OpenXML SDK level because OpenXML SDK does not do pagination. For further details, see the duplicate question link: [**How to access OpenXML content by page number?**](https://stackoverflow.com/questions/39992870/how-to-access-openxml-content-by-page-number) – kjhughes Mar 08 '18 at 21:50
  • I see. Thanks for that link. I'll study this further. – Michael Mar 08 '18 at 22:30

0 Answers0