Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Jan 17, 2012 7:30 pm

Hi,

I want to create a Table with two Rows in the Header and the two rows have different count of cells.
It shout seems like the screenshot.

I tried it with the following code:

Dim table As Spire.Doc.Table = New Spire.Doc.Table(docMonatsbericht)
table.ResetCells(dtDaten.Rows.Count + 2, 7)

Dim row As TableRow
Dim intWidth As Integer


' Überschrift Zeile 1

row = table.Rows(0)
row.IsHeader = True
row.Height = 35
row.HeightType = TableRowHeightType.Exactly
row.RowFormat.BackColor = Color.Gray

For i As Integer = 0 To 6


row.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
Dim p As Paragraph = row.Cells(i).AddParagraph()
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center

Select Case i
Case 0
txtRange = p.AppendText("Chance")
intWidth = 65
Case 1, 4
txtRange = p.AppendText("Angebots-summe")
intWidth = 65
Case 2, 5
txtRange = p.AppendText("Anzahl")
intWidth = 65
Case 3, 6
txtRange = p.AppendText("AE")
intWidth = 65

End Select

row.Cells(i).Width = intWidth

Next i


' Überschrift Zeile 2

row = table.Rows(1)
row.IsHeader = True
row.Height = 35
row.HeightType = TableRowHeightType.Exactly
row.RowFormat.BackColor = Color.Gray

For i As Integer = 0 To 2


row.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
Dim p As Paragraph = row.Cells(i).AddParagraph()
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center

Select Case i
Case 0
txtRange = p.AppendText("")
intWidth = 65
Case 1
txtRange = p.AppendText("Aktuelle Jahr")
intWidth = 3 * 65
Case 2
txtRange = p.AppendText("kummuliert")
intWidth = 3 * 65

End Select

row.Cells(i).Width = intWidth

Next i



But I get also seven cells in the second row. How can I reduce the count on three cells?


Thanks for answer,
Oliver

albatros
 
Posts: 2
Joined: Thu Dec 15, 2011 10:08 pm

Wed Jan 18, 2012 4:15 am

Hello Oliver,
Thank you for your inquiry.
You can use the method "table.ApplyHorizontalMerge()" to achieve your purpose. Your can use the following code to have a try.

Code: Select all
Dim table As Spire.Doc.Table = New Spire.Doc.Table(docMonatsbericht)
table.ResetCells(dtDaten.Rows.Count + 2, 7)

Dim row As TableRow
Dim intWidth As Integer


' Überschrift Zeile 1

row = table.Rows(0)
row.IsHeader = True
row.Height = 35
row.HeightType = TableRowHeightType.Exactly
row.RowFormat.BackColor = Color.Gray

For i As Integer = 0 To 6


row.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
Dim p As Paragraph = row.Cells(i).AddParagraph()
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center

Select Case i
Case 0
txtRange = p.AppendText("Chance")
intWidth = 65
Case 1, 4
txtRange = p.AppendText("Angebots-summe")
intWidth = 65
Case 2, 5
txtRange = p.AppendText("Anzahl")
intWidth = 65
Case 3, 6
txtRange = p.AppendText("AE")
intWidth = 65

End Select

row.Cells(i).Width = intWidth

Next i


' Überschrift Zeile 2

table.ApplyHorizontalMerge(1, 1, 3);
table.ApplyHorizontalMerge(1, 4, 6
row = table.Rows(1)
row.IsHeader = True
row.Height = 35
row.HeightType = TableRowHeightType.Exactly
row.RowFormat.BackColor = Color.Gray

For i As Integer = 0 To 6

row.Cells(i).CellFormat.VerticalAlignment = VerticalAlignment.Middle
Dim p As Paragraph = row.Cells(i).AddParagraph()
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center

Select Case i
Case 0
txtRange = p.AppendText("")
intWidth = 65
Case 1
txtRange = p.AppendText("Aktuelle Jahr")
Case 4
txtRange = p.AppendText("kummuliert")
End Select

row.Cells(i).Width = intWidth

Next i


If you still have this problem, please don't hesitate to contact us at any time.
Have a great day.

BR
Suvi
e-iceblue sopport
User avatar

Suvi.Wu
 
Posts: 154
Joined: Thu Oct 20, 2011 2:53 am

Wed Jan 18, 2012 8:35 pm

HI Suvi,

it work's. :P

Thanks a lot. Great and fast job.


I wish you also a good day.

albatros
 
Posts: 2
Joined: Thu Dec 15, 2011 10:08 pm

Thu Jan 19, 2012 1:59 am

Hello albatros,

That's great, if you have any other questions, please feel free to contact us at any time.

BR
Suvi
e-iceblue support
User avatar

Suvi.Wu
 
Posts: 154
Joined: Thu Oct 20, 2011 2:53 am

Return to Spire.Doc