2 Rows in the Table Header

Technical support for Spire.Doc

Moderator: iceblue support

2 Rows in the Table Header

Postby albatros » 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
You do not have the required permissions to view the files attached to this post.
albatros
 
Posts: 2
Joined: Thu Dec 15, 2011 10:08 pm

Re: 2 Rows in the Table Header

Postby Suvi.Wu » 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: 156
Joined: Thu Oct 20, 2011 2:53 am

Re: 2 Rows in the Table Header

Postby albatros » 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

Re: 2 Rows in the Table Header

Postby Suvi.Wu » 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: 156
Joined: Thu Oct 20, 2011 2:53 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests