Free Support Forum - aspose.com

Differences between table widths when setting horizontal merge to previous in version 11.6.0 and 11.9.0

Hi,


We have created unit tests for every functionality of Aspose.Words we use in our software. That is when we came across the following difference when running the following test:
Create 4 rows with 3 columns, set for every cell the horizontal merge cell formatting to previous.

The result however was in 11.6.0 that the table would have the full width of the page, in 11.9.0 that table is only one character wide.

Code:
Dim objBuilder As New DocumentBuilder()

Dim objTable As Tables.Table = objBuilder.StartTable()
    <span style="color:blue;">Dim</span> intRowIndex <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 0
    <span style="color:blue;">While</span> (intRowIndex < 4)

        objBuilder.Bold = (intRowIndex = 0) <span style="color:green;">' Set the header bold</span>

        <span style="color:blue;">Dim</span> intColumnIndex <span style="color:blue;">As</span> <span style="color:blue;">Integer</span> = 0
        <span style="color:blue;">While</span> (intColumnIndex < 3)

            <span style="color:blue;">Dim</span> objCell <span style="color:blue;">As</span> Tables.<span style="color:#2b91af;">Cell</span> = objBuilder.InsertCell()

            strValue = strValue.ToLower()
            <span style="color:blue;">Select</span> <span style="color:blue;">Case</span> strOption.ToLower()
                <span style="color:blue;">Case</span> <span style="color:#a31515;">"horizontalmerge"</span>
                    objCell.CellFormat.HorizontalMerge = Tables.<span style="color:#2b91af;">CellMerge</span>.Previous
                <span style="color:blue;">Case Else</span>
                    <span style="color:blue;">Throw</span> <span style="color:blue;">New</span> <span style="color:#2b91af;">Exception</span>(<span style="color:#a31515;">"Option not supported"</span>)
            <span style="color:blue;">End</span> <span style="color:blue;">Select</span>

            objBuilder.Write(<span style="color:blue;">String</span>.Format(<span style="color:#a31515;">"option: {0}, value: {1}"</span>, strOption, strValue))

            intColumnIndex += 1
        <span style="color:blue;">End</span> <span style="color:blue;">While</span>

        objBuilder.EndRow()

        intRowIndex += 1
    <span style="color:blue;">End</span> <span style="color:blue;">While</span>
    objBuilder.InsertCell()

    objBuilder.EndTable()</pre><pre style="background-color: white;"><font face="Times New Roman"><span style="white-space: normal;">Would your please let us know if you can replicate this behaviour and if it is expected?</span></font></pre><pre style="background-color: white;"><pre><font face="Times New Roman"><span style="white-space: normal;">With kind regards,</span></font></pre><pre><font face="Times New Roman"><span style="white-space: normal;">Sjoerd van Loon<br>Software Engineer, Infoland BV</span></font></pre></pre></div>

Hi Sjoerd,


Thanks for your inquiry. I have modified your code, please see the highlighted section of code and read following documentation link for your kind reference. I have attached the output Doc file with this post.
http://www.aspose.com/docs/display/wordsnet/Working+with+Merged+Cells


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;mso-font-kerning:0pt;
mso-no-proof:yes”> Dim strValue As String = “some
text”<o:p></o:p>

Dim strOption As String = "horizontalmerge"

Dim objBuilder As New DocumentBuilder()

Dim objTable As Tables.Table = objBuilder.StartTable()

Dim intRowIndex As Integer = 0

While (intRowIndex < 4)

objBuilder.Bold = (intRowIndex = 0) ' Set the header bold

Dim intColumnIndex As Integer = 0

While (intColumnIndex < 3)

Dim objCell As Tables.Cell = objBuilder.InsertCell()

If intColumnIndex = 0 Then

objCell.CellFormat.HorizontalMerge = Tables.CellMerge.First

End If

strValue = strValue.ToLower()

Select Case strOption.ToLower()

Case "horizontalmerge"

If intColumnIndex > 0 Then

objCell.CellFormat.HorizontalMerge = Tables.CellMerge.Previous

End If

Case Else

Throw New Exception("Option not supported")

End Select

objBuilder.Write(String.Format("option: {0}, value: {1}", strOption, strValue))

intColumnIndex += 1

End While

objBuilder.EndRow()

intRowIndex += 1

End While

Dim objCell2 As Tables.Cell = objBuilder.InsertCell()

objCell2.CellFormat.HorizontalMerge = Tables.CellMerge.None

objBuilder.InsertCell()

objBuilder.InsertCell()

objBuilder.EndRow()

objBuilder.EndTable()

objBuilder.Document.Save("D:\AsposeOut.doc")