Spacing between Table Text(content) and Table border

hi,
i have an issue when i use table in the header of the word document.the problem is there is a gap between the table text(content) and the table border(refer file name "HeaderWordGap.doc"). But i dont have the same mentioned problem with another word file where i am using the same table in the header(refer file name "HeaderWordNormal.doc").So pls give me a solution so that there is no gap between table text(content) and border.
Also my word header output(HeaderWordGap.doc) should be matching pdf header output(HeaderPdfNormalGap.pdf). i am using the following code and template(from which i will clone the 7th table into word document file) and bind the content to the merge fields(AssessmentName,CourseName) using builder.InsertHtml() function.
waiting for your earliest reply as i need to answer my client.

Following is the code to include header in the word file:

Private Sub IncludeHeader(ByVal currentDoc As Aspose.Words.Document, ByVal currentBuilder As Aspose.Words.DocumentBuilder)
Dim currentNode As Aspose.Words.Node = currentBuilder.CurrentParagraph
Dim param As Boolean = True
currentDoc.Sections(0).PageSetup.DifferentFirstPageHeaderFooter = False

Dim ObjHeader As New Aspose.Words.HeaderFooter(currentDoc, HeaderFooterType.HeaderPrimary)
currentDoc.Sections(0).HeadersFooters.Add(ObjHeader)

Dim sourceSection As Aspose.Words.Section
If _AssessmentType = DataTransferObjects.Asset.AssessmentAssetSubTypeEnum.PaperTest Then
currentBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary)
'If Convert.ToString(_PrintableItems("Header")).IndexOf("#=") <> -1 Then
' Call BindHTML(currentBuilder, Convert.ToString(_PrintableItems("Header")).Substring(0, Convert.ToString(_PrintableItems("Header")).IndexOf("#=")))
' If _PrintSettingDTO.IncludePageNumber Then
' currentBuilder.InsertField("PAGE", "")
' End If
' Call BindHTML(currentBuilder, Convert.ToString(_PrintableItems("Header")).Substring(Convert.ToString(_PrintableItems("Header")).IndexOf("#=") + 2))
'Else
Call BindHTML(currentBuilder, _PrintableItems("Header"), param)
' If _PrintSettingDTO.IncludePageNumber Then
' currentBuilder.InsertField("PAGE", "")
' End If
'End If
Else
If _SubmittedAssessment Then
sourceSection = currentDoc.ImportNode(CType(_arrHiddenTables(7), Section).Clone(True), True)
sourceSection.Body.Tables(0).FirstRow.RowFormat.HeightRule = HeightRule.Exactly
ObjHeader.AppendChild(sourceSection.Body.Tables(0).Clone(True))
currentBuilder.MoveToMergeField("StudentName")
currentBuilder.Writeln(_PrintableItems("StudentName"))
currentBuilder.MoveToMergeField("SubmissionDate")
currentBuilder.InsertHtml(_PrintableItems("SubmissionDate"))
'currentBuilder.Write(CType(_PrintableItems("SubmissionDate"), DateTime).ToString("M/d/yyyy"))
currentBuilder.MoveToMergeField("Grade")
currentBuilder.InsertHtml(_PrintableItems("Grade"))
' Call BindHTML(currentBuilder, _PrintableItems("Grade"))
currentBuilder.MoveToMergeField("GradeImage")
currentBuilder.InsertHtml(_PrintableItems("GradeImage"))
'Call BindHTML(currentBuilder, _PrintableItems("GradeImage"))
currentBuilder.MoveToMergeField("NoOfAttempts")
currentBuilder.Write(_PrintableItems("NoOfAttempts"))
currentBuilder.MoveToMergeField("AttemptedQuestions")
currentBuilder.Write(_PrintableItems("AttemptedQuestions"))
Else
sourceSection = currentDoc.ImportNode(CType(_arrHiddenTables(6), Section).Clone(True), True)
'sourceSection.Body.Tables(0).FirstRow.RowFormat.Borders.Bottom.DistanceFromText = 1.5
' sourceSection.Body.Tables(0).FirstRow.RowFormat.Height = 1


' sourceSection.Body.Tables(0).FirstRow.RowFormat.ClearCellPadding()

'' sourceSection.Body.Tables(0).FirstRow.RowFormat.BottomPadding = 0
'sourceSection.Body.Tables(0).FirstRow.RowFormat.TopPadding = 0
'sourceSection.Body.Tables(0).FirstRow.RowFormat.LeftPadding = 0
'sourceSection.Body.Tables(0).FirstRow.RowFormat.RightPadding = 0
'' sourceSection.Body.Tables(0).FirstRow.RowFormat.HeightRule = HeightRule.Auto
'sourceSection.Body.Tables(0).FirstRow.RowFormat.AllowAutoFit = True
'' sourceSection.Body.Tables(0).FirstRow.RowFormat.Borders.Bottom.DistanceFromText = 0
'' sourceSection.Body.Tables(0).FirstRow.LastCell.CellFormat.FitText = True

ObjHeader.AppendChild(sourceSection.Body.Tables(0).Clone(True))
currentBuilder.MoveToMergeField("CourseName")
If _PrintSettingDTO.IncludeCourseName Then
currentBuilder.Write(_PrintableItems("CourseName"))
End If
currentBuilder.MoveToMergeField("AssessmentName")
If _PrintSettingDTO.IncludeCourseName Then
currentBuilder.Write(_PrintableItems("AssessmentName"))
End If
End If
End If

currentBuilder.MoveTo(currentNode)
End Sub


________________________________

Following is the code to clone the cell from template to word document:


Private Sub CloneCellFormat(ByVal sourceCellFormat As Aspose.Words.CellFormat, ByVal destinationCellFormat As Aspose.Words.CellFormat)
With destinationCellFormat.Borders
'.Color = sourceCellFormat.Borders.Color
.DistanceFromText = sourceCellFormat.Borders.DistanceFromText
.LineStyle = sourceCellFormat.Borders.LineStyle
.LineWidth = sourceCellFormat.Borders.LineWidth
.Shadow = sourceCellFormat.Borders.Shadow
End With
destinationCellFormat.BottomPadding = sourceCellFormat.BottomPadding
destinationCellFormat.HorizontalMerge = sourceCellFormat.HorizontalMerge
destinationCellFormat.LeftPadding = sourceCellFormat.LeftPadding
destinationCellFormat.Orientation = sourceCellFormat.Orientation
destinationCellFormat.RightPadding = sourceCellFormat.RightPadding
'destinationCellFormat.FitText = sourceCellFormat.FitText
'destinationCellFormat.BottomPadding = sourceCellFormat.BottomPadding
'destinationCellFormat.WrapText = sourceCellFormat.WrapText
destinationCellFormat.FitText = True
destinationCellFormat.BottomPadding = 0
destinationCellFormat.WrapText = True

With destinationCellFormat.Shading
'.BackgroundPatternColor = sourceCellFormat.Shading.BackgroundPatternColor
'.ForegroundPatternColor = sourceCellFormat.Shading.ForegroundPatternColor
.Texture = sourceCellFormat.Shading.Texture
End With
destinationCellFormat.TopPadding = sourceCellFormat.TopPadding
destinationCellFormat.VerticalAlignment = sourceCellFormat.VerticalAlignment
destinationCellFormat.VerticalMerge = sourceCellFormat.VerticalMerge
destinationCellFormat.Width = sourceCellFormat.Width
End Sub
__________________________________

Following is the code to bind the content to merge fields(Assessmentname,CourseName):

Private Sub BindHTML(ByVal builder As Aspose.Words.DocumentBuilder, ByVal Content As String, Optional ByVal param As Boolean = False)
Dim intCount As Integer
Dim strValue As String
Dim strB As New StringBuilder
Dim count As Integer = 0
Content = Content.Replace(" ", "  ")
Dim _CurrentNode As Aspose.Words.Node = builder.CurrentParagraph
If Content.IndexOf("<") > -1 And Content.IndexOf(">") > -1 Then
If Content.IndexOf("FONT color=#") > -1 Or Content.IndexOf("font color=#") > -1 Then
Content = Content
End If

If Content.IndexOf("font color=") > -1 Or Content.IndexOf("FONT color=") > -1 Or Content.IndexOf("color=") > -1 Then
Content = Content.Replace("color=", "color=#")
End If
''If Content.IndexOf("FONT") > -1 And Content.IndexOf("style") > -1 Then
'' Content = Content.Replace("FONT style", "SPAN style")
'' Content = Content.Replace("", "")
''End If
If Content.IndexOf("FONT") > -1 Or Content.IndexOf("style") > -1 Then
Dim arr() As String = Content.Split(">")
Dim intCheck(arr.Length) As Integer
For intCount = 0 To arr.Length - 1
arr(intCount) = arr(intCount) + ">"
If arr(intCount).IndexOf("FONT") > -1 And arr(intCount).IndexOf("color") > -1 Then
count = count + 1
intCheck(count) = 0
End If

If arr(intCount).IndexOf("FONT") > -1 And arr(intCount).IndexOf("style") > -1 Then
strValue = arr(intCount)
strValue = Replace(strValue, "FONT", "SPAN")
arr(intCount) = strValue
count = count + 1
intCheck(count) = 1
End If

If arr(intCount).IndexOf("") > -1 Then
If intCheck(count) = 1 Then
strValue = arr(intCount)
strValue = Replace(strValue, "", "")
arr(intCount) = strValue
End If
If (count <= 0) Then
count = 0
Else
count = count - 1
End If
End If
Next

For intCount = 0 To arr.Length - 2
strB.Append(arr(intCount))
Next
Content = strB.ToString()
Content = Content.Replace("=##", "=#")
End If

If Content.IndexOf(" -1 Then
Content = IndentCode(builder, Content)
End If


Try
'If (Content.IndexOf("= 0) Then
' Content = Content.Replace("

", block)
' Content = Content.Replace("

", "")
' Content = Content.Replace("

", "")
' Content = Content.Replace("

", "
")
' Content = Content.Replace("
", "")
'End If

builder.InsertHtml(Content)

Catch ex As System.FormatException
Content = Content.Replace("0in", "0pt")
builder.InsertHtml(Content)
End Try
Else
builder.Write(System.Web.HttpUtility.HtmlDecode(Content))
End If
Do While (Not _CurrentNode Is Nothing)
If _CurrentNode.NodeType = NodeType.Paragraph Then
With CType(_CurrentNode, Aspose.Words.Paragraph)
.ParagraphFormat.SpaceAfterAuto = False
.ParagraphFormat.SpaceAfter = 0
If Not param Then
Call ChangeFont(.Runs)
End If
End With
End If
_CurrentNode = _CurrentNode.NextSibling
Loop
End Sub
____________________________

Following is the code to import tables from Template_0.doc to aspose.word document:


Private Sub ImportTables()
Dim _NodeList As Aspose.Words.NodeList = templateDoc.SelectNodes("//Section")
Dim _Section As Aspose.Words.Section

Dim intSections As Integer
For intSections = 0 To _NodeList.Count - 1
_Section = doc.ImportNode(_NodeList(intSections), True)
Call MakeTableNotBreakable(_Section.Body.Tables(0))
_arrHiddenTables.Add(_Section)
Next intSections
End Sub
__________________________
Private Sub ImportTable(ByVal currentTable As Aspose.Words.Table, Optional ByVal currentBuilder As DocumentBuilder = Nothing)
If currentBuilder Is Nothing Then
currentBuilder = builder
End If
Dim intRows, intColumns, intParagraphs As Int16
Dim _Row As Aspose.Words.Row
Dim _Column As Aspose.Words.Cell
Dim _Paragraph As Aspose.Words.Paragraph

For intRows = 0 To currentTable.Rows.Count - 1
_Row = currentTable.Rows(intRows)
For intColumns = 0 To _Row.Cells.Count - 1
_Column = _Row.Cells(intColumns)
currentBuilder.InsertCell()
Call CloneCellFormat(_Column.CellFormat, currentBuilder.CellFormat)
For intParagraphs = 0 To _Column.Paragraphs.Count - 1
_Paragraph = _Column.Paragraphs(intParagraphs)
Call CloneParagraph(_Paragraph, currentBuilder.CurrentParagraph)
Call CloneParagraphFormat(_Paragraph.ParagraphFormat, currentBuilder.CurrentParagraph.ParagraphFormat)
Next intParagraphs
Next intColumns
currentBuilder.EndRow()
Next intRows
End Sub

I have attached screen shots for your reference.

With regards,
I Prabhaharan

The gap in HeaderWordGap.doc is caused by two extra paragraph marks in the end of Test cell text. That is probably because some extra

tags are inserted during merge with the «AssessmentName» field. If you want to avoid this and cannot prevent inserting it from your data you need to check for the presence of empty paragraphs in the cell after InsertHtml is executed and remove them when found.

Hope this helps. Please let me know if you need further help with this issue.

hi,

Thanks for yours suggestion. As per your suggestion i verified my code, but couldnt find any spaces in my code and also the code which i sent you in my previous mail doesnt contain any

tags(code with

tags in "Try" block was commented.) Also it is important to note that the same code is used in two documents(refer "HeaderWordNormal.doc" and "HeaderWordGap.doc"). But one document is having gap between table text and table border while the other document is not having gap between table text and table border.

So pls give me a solution for this as early as possible. Refer my previous mail for code and screen shots.

Thanks and Regards,

I Prabhaharan

I cannot reproduce the error using the data provided. Everything seems to work correctly in my test. If you are absolutely sure that this is not the inserted HTML data that cause extra paragraphs marks to appear, then try to compose a small test project reproducing the error and attach it here.

Best regards,