none
Columns Balancing RRS feed

  • Question

  • Hi,

    Text in a document can be splitted on columns. And columns can be "balanced" - text in columns distributed to make columns heights equal. The questions is what algorithm Word uses to balance columns?

    I'm trying display text exactly as Word does. Any tips?
    Thursday, February 25, 2010 2:30 PM

All replies

  • Hi XMan AT!

    Did you mean column widths instead of column heights?
    I don't know about any algorithm but have you tried playing around with the EqualWidth property
    of the DocumentFormat.OpenXML.Wordprocessing.Columns object?

    Friday, February 26, 2010 3:36 AM
  • Hi XMan AT,

    Thanks for your question.

    The Open XML SDK is a collection of classes that let you create and manipulate Open XML documents. It is NOT a replacement for the Office Object Model. It does NOT provide application behaviors such as layout (ex. pagination of WordprocessingML documents), formula calculation (which is very common in Excel) or recalculation functionality.

    Your requirement of columns balancing is some kinds of layout application behavior, which Open XML SDK doesn't support. You could try to find other technology to achieve this.

    Thanks,

    Lu

    Friday, February 26, 2010 8:31 AM
  • Hi XMan AT!

    Did you mean column widths instead of column heights?
    I don't know about any algorithm but have you tried playing around with the EqualWidth property
    of the DocumentFormat.OpenXML.Wordprocessing.Columns object?


    No, I mean heights. If you will create new document, then insert 5 paragraphs, make two columns, and then insert section break - paragraphs will be distributed between columns. First 3 paragraphs will be in first column and 2 paragrphs will go to the second. I need to find an algorithm how to distribute text - what text should be in first column and what in second.
    Friday, February 26, 2010 8:32 AM
  • Hi XMan AT,

    Thanks for your question.

    The Open XML SDK is a collection of classes that let you create and manipulate Open XML documents. It is NOT a replacement for the Office Object Model. It does NOT provide application behaviors such as layout (ex. pagination of WordprocessingML documents), formula calculation (which is very common in Excel) or recalculation functionality.

    Your requirement of columns balancing is some kinds of layout application behavior, which Open XML SDK doesn't support. You could try to find other technology to achieve this.

    Thanks,

    Lu

    Yes, I understand what Open XML SDK will not help me with this. May be this question more related with Office features and this is wrong thread I chose to post in... But... In Open XML specification I can find descriptions for many algorithms like table width calculation, and about columns  all what was written is:

    In terms of column layout,

    balancing is the act of attempting to ensure that the number of lines in each column is equivalent (rather than completely filling one column before populating the next).

    :-(
    Friday, February 26, 2010 9:32 AM
  • Hi XMan AT,

    Thanks for your reply.

    Could you give an example of the algorithms? Do you mean the Width property of the Column? You can set the width of a column using Open XML SDK, however, if you need to keep the columns balanced, there are many other factors interact with each other which you need to take into consideration such as the font of the text. So this may be a very complex task to achieve using Open XML SDK. Even if you make it, you cannot keep the columns balanced dynamically (as what you can do in Word). So it is not suggested to use Open XML SDK to solve this problem.

    Hope this helps. If you have any question, please let me know.

    Thanks,

    Lu

    Thursday, March 4, 2010 2:51 AM
  • > Could you give an example of the algorithms?

    Example (table width calculation):

    "Office Open XML. Document Interchange Specification"

    §2.18.94

    Fixed Width Table Layout - This method of table layout uses the preferred widths on the table items to generate the final sizing of the table, but does not change that size regardless of the contents of each table cell, hence the table is fixed width.

    [Guidance: Although an application may choose to use a different process, this layout could be performed as follows:
     The table grid is used to create the set of shared columns in the table and their initial widths as defined in the tblGrid element (§2.4.44)
     The table’s total width is defined based on the tblW property (§2.4.61) – if it is set to auto or nil, then the width is not yet determined and will be specified using the row and cell information.
     The first table row is read and the initial number of grid units before the row starts is skipped. The width of the skipped grid columns is set using the wBefore property (§2.4.83).
     The first cell is placed on the grid, and the width of the specified grid column span set by gridSpan (§2.4.13) is set based on the tcW property (§2.4.68).
     Each additional cell is placed on the grid.
     If at any stage, the preferred width requested for the cells exceeds the preferred width of the table, then each grid column is proportionally reduced in size to fit the table width.
     If the grid is exceeded (e.g. tblGrid specifies three grid columns, but the second cell has a gridSpan of three), the grid is dynamically increased with a default width for the new grid column.
     For each subsequent row, cells are placed on the grid, and each grid column is adjusted to be the maximum value of the requested widths (if the widths do not agree) by adding width to the last cell that ends with that grid column. Again, if at any point, the space requested for the cells exceeds the width of the table, then each grid column is proportionally reduced in size to fit the table width.
    end guidance]

    ...

    And you can find more examples in the specification :-)

    > Do you mean the Width property of the Column?

    No, HEIGHTS, I need algorithm to calculate heights.

    > So this may be a very complex task...

    I'm sure it is. But it would be good if I knew at least basic steps how Word calculates columns.

    Thanks for replay.

    Tuesday, April 13, 2010 8:00 AM
  • > Could you give an example of the algorithms?

    Example (table width calculation):

    "Office Open XML. Document Interchange Specification"

    §2.18.94

    Fixed Width Table Layout - This method of table layout uses the preferred widths on the table items to generate the final sizing of the table, but does not change that size regardless of the contents of each table cell, hence the table is fixed width.

    [Guidance: Although an application may choose to use a different process, this layout could be performed as follows:
     The table grid is used to create the set of shared columns in the table and their initial widths as defined in the tblGrid element (§2.4.44)
     The table’s total width is defined based on the tblW property (§2.4.61) – if it is set to auto or nil, then the width is not yet determined and will be specified using the row and cell information.
     The first table row is read and the initial number of grid units before the row starts is skipped. The width of the skipped grid columns is set using the wBefore property (§2.4.83).
     The first cell is placed on the grid, and the width of the specified grid column span set by gridSpan (§2.4.13) is set based on the tcW property (§2.4.68).
     Each additional cell is placed on the grid.
     If at any stage, the preferred width requested for the cells exceeds the preferred width of the table, then each grid column is proportionally reduced in size to fit the table width.
     If the grid is exceeded (e.g. tblGrid specifies three grid columns, but the second cell has a gridSpan of three), the grid is dynamically increased with a default width for the new grid column.
     For each subsequent row, cells are placed on the grid, and each grid column is adjusted to be the maximum value of the requested widths (if the widths do not agree) by adding width to the last cell that ends with that grid column. Again, if at any point, the space requested for the cells exceeds the width of the table, then each grid column is proportionally reduced in size to fit the table width.
    end guidance]

    ...

    And you can find more examples in the specification :-)

    > Do you mean the Width property of the Column?

    No, HEIGHTS, I need algorithm to calculate heights.

    > So this may be a very complex task...

    I'm sure it is. But it would be good if I knew at least basic steps how Word calculates columns.

    Thanks for reply.

    Tuesday, April 13, 2010 8:01 AM