Hi thank you for your answer.
In the following code you can see the 3 functions I use to define the headers, to create the table and to add rows to the created table.
I can take advantage of your patience to figure out if I wrote nonsense? thank you
===============================================================
Code:
Public Sub DefineHeader(ByVal Filename As String, Optional ByVal Width As Single = 0, Optional ByVal Height As Single = 0, Optional LeftPosition As Single = 0, Optional TopPosition As Single = 0)
Dim section As Section = _document.LastSection()
If _OddAndEvenPagesHeaderFooter Then
Dim header As HeaderFooter = section.Headers.Primary
header.AddParagraph(vbTab & "Odd Page Header")
header = section.Headers.EvenPage
header.AddParagraph("Even Page Header")
Else
Dim header As HeaderFooter
If Filename <> "" Then
header = section.Headers.Primary
Dim headerImg = header.AddImage(theDirectory & "\images\" & Filename)
If Width <> 0 Then headerImg.Width = Unit.FromCentimeter(Width)
If Height <> 0 Then headerImg.Height = Unit.FromCentimeter(Height)
If LeftPosition <> 0 Then headerImg.Left = Unit.FromCentimeter(LeftPosition)
If TopPosition <> 0 Then headerImg.Top = Unit.FromCentimeter(TopPosition)
_currHeight = headerImg.Height.Centimeter
End If
End If
End Sub
================================================================
Code:
Public Function CreateTable(ByVal Intestazione() As String, ByVal ColsWidth() As Single, ByVal ColsAlignment() As Integer, ByVal Top As Single) As MigraDoc.DocumentObjectModel.Tables.Table
Dim Table = _document.LastSection.AddTable
Table.Borders.Width = 0.5
Table.Format.Font.ApplyFont(_currFont)
' table.Format.SpaceBefore = Unit.FromCentimeter(Top)
For i = 0 To ColsWidth.Count - 1
Dim column = Table.AddColumn(Unit.FromCentimeter(ColsWidth(i)))
column.Format.Alignment = ColsAlignment(i)
Next
Dim row = Table.AddRow()
row.Shading.Color = Colors.White
row.HeadingFormat = True
Dim MaxRowHeight As Single = 0
For i = 0 To Intestazione.Count - 1
Dim cell = row.Cells(i)
cell.AddParagraph(Intestazione(i))
Dim rowheight As Single
GetTextMeasure(Intestazione(i))
rowheight = (_currWidth / ColsWidth(i)) + 1
rowheight *= _currHeight
MaxRowHeight = IIf(MaxRowHeight < rowheight, rowheight, MaxRowHeight)
Next
row.Height = Unit.FromCentimeter(MaxRowHeight)
row.HeightRule = Tables.RowHeightRule.Exactly
_currHeight += MaxRowHeight
Return Table
End Function
===================================================================
Code:
Public Sub AddRowTable(ByRef Table As MigraDoc.DocumentObjectModel.Tables.Table, ByVal CellContent() As String, ByVal ColsAlignment() As Integer, Optional ByVal Top As Single = 0, Optional ByVal PageBreak As Boolean = False)
Table.Borders.Width = 0.5
Table.Format.Font.ApplyFont(_currFont)
Dim row = Table.AddRow()
row.Shading.Color = Colors.White
row.HeadingFormat = False
row.Format.PageBreakBefore = PageBreak
Dim MaxRowHeight As Single = 0
For i = 0 To CellContent.Count - 1
Dim cell = row.Cells(i)
cell.AddParagraph(CellContent(i))
cell.Format.Alignment = ColsAlignment(i)
Dim rowheight As Single
GetTextMeasure(CellContent(i))
rowheight = (_currWidth / row.Item(i).Column.Width.Centimeter) + 1
rowheight *= _currHeight
MaxRowHeight = IIf(MaxRowHeight < rowheight, rowheight, MaxRowHeight)
Next
row.Height = Unit.FromCentimeter(MaxRowHeight)
row.HeightRule = Tables.RowHeightRule.Exactly
_currHeight += MaxRowHeight
End Sub