HI,
I am trying to add a table to a document after a paragraph using "Infragistics.Documents.Word" with the code inserted below.
However, the table always ends up on a second page instead of right after the paragraph. What am I doing wrong?
Kind regards
Kai-Inge
Private Sub UltraButton2_Click(sender As Object, e As EventArgs) Handles UltraButton2.Click Dim docTest = New Document() 'doc.DocumentPropertie()
'***************************************************************************************************** '***** FONTS '*****************************************************************************************************
Dim font As Infragistics.Documents.Word.Font = docTest.CreateFont() font.Reset() font.Bold = False font.Size = 11 font.Name = "Arial"
' Add a paragraph to the Document Dim para As Paragraph = docTest.ContentBlocks.AddParagraph()
Dim sec As Section = docTest.Sections.Add(para) ' Header
' Add text to Paragraph para.ContentRuns.AddNewLine() para.ContentRuns.AddNewLine()
para.ContentRuns.AddNewLine() para.ContentRuns.AddTextRun("Some text", font) para.ContentRuns.AddNewLine() para.ContentRuns.AddTextRun("Some text", font) para.ContentRuns.AddNewLine() para.ContentRuns.AddNewLine()
para.ContentRuns.AddNewLine()
para.ContentRuns.AddTextRun("Some text") para.ContentRuns.AddNewLine() para.ContentRuns.AddNewLine() para.ContentRuns.AddTextRun("Some text") '******************************************************************************************* ' table '*******************************************************************************************
Dim tblSampleDescr As Table = docTest.ContentBlocks.AddTable
tblSampleDescr.Properties.BorderProperties.Style = TableBorderStyle.[Double]
Dim columnSample As TableColumn = tblSampleDescr.Columns.Add()
Dim rowSample As TableRow = tblSampleDescr.Rows.Add()
Dim cell1forSampleRow As TableCell = tblSampleDescr.Rows(0).Cells.Add() Dim paraSampleRowCell1 As Paragraph = cell1forSampleRow.ContentBlocks.AddParagraph() paraSampleRowCell1.Properties.Alignment = ParagraphAlignment.Left
paraSampleRowCell1.ContentRuns.AddTextRun("Sample no.1", font)
Dim cell2forSampleRow As TableCell = tblSampleDescr.Rows(0).Cells.Add() Dim paraSampleRowCell2 As Paragraph = cell2forSampleRow.ContentBlocks.AddParagraph()
paraSampleRowCell2.Properties.Alignment = ParagraphAlignment.Left paraSampleRowCell2.ContentRuns.AddTextRun("--Some info on sample no. 1--", font) '*******************************************************************************************
'***************************************************************************************************** '**** Footer '*****************************************************************************************************
Dim footerPara As Paragraph = sec.FooterAllPages.ContentBlocks.AddParagraph() ' The footer text alignment is set to right footerPara.Properties.Alignment = ParagraphAlignment.Right ' Display Text in Footer footerPara.ContentRuns.AddTextRun("some strFooterText") ' Add Page numbers to the Footer footerPara.ContentRuns.AddPageNumberField(PageNumberFieldFormat.Ordinal)
docTest.Save("c:\testfolder\test.docx")
System.Diagnostics.Process.Start("c:\testfolder\test.docx")
End Sub
Hi Dimitar,
Thanks for following up.
I managed to solve it.
Best wishes
Kai
Hello,
I am just checking about the progress of this issue. Let me know if you need my further assistance on this issue.
Thank you for using Infragistics Components.
Hi,
Thank you for contacting Infragistics Developer Support.
What you could do in order to prevent this behavior is, instead of using a new section created by you, to use the FinalSection property of the word document. To do that remove this line:
Dim sec As Section = docTest.Sections.Add(para)
And change the following line:
Dim footerPara As Paragraph = sec.FooterAllPages.ContentBlocks.AddParagraph()
To:
Dim footerPara As Paragraph = docTest.FinalSection.FooterAllPages.ContentBlocks.AddParagraph()
Please let me know if you have any additional questions.