I am trying to insert a dynamic table into a .DOC, then save as .PDF. It seems that building a table within a numbered list does not play nice. You will notice that the list above the table loses its numbering.
I have commented out some code, which you can un-comment to see how I have tried to work around this issue. The results are different, but still messed up. I have also tried turning off numbering, and then turning it back on, to no avail.
How do I go about this, so that the table is still in the numbered paragraph, and without throwing off the numbering, or the indent of the table?
.DOC file attached.
Code:
--------------------------------------
Imports Aspose.Words
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim doc As Document = New Document(Server.MapPath(“Table Test.doc”))
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
’ Move to the bookmark
builder.MoveToBookmark(“TestTable”)
builder.CellFormat.Borders.LineStyle = LineStyle.Single
builder.CellFormat.FitText = True
’ Set the font size
Dim font As Font = builder.Font
font.Size = 8
’ This almost works, but loses indent and also removes number.
'builder.ListFormat.RemoveNumbers()
builder.StartTable()
WriteCell(builder, 0.45, “Cell 1”)
WriteCell(builder, 0.63, “Another” & vbCrLf & “Cell”)
WriteCell(builder, 0.76, “Yet” & vbCrLf & “Another” & vbCrLf & “Cell” & vbCrLf & “Date”)
builder.EndRow()
WriteCell(builder, 0.45, “4”)
WriteCell(builder, 0.63, “20%”)
WriteCell(builder, 0.76, “5/5/2005”)
builder.EndRow()
builder.EndTable()
’ Delete the bookmark text. Uncomment to see additional behavior of removing bookmark text.
'doc.Range.Bookmarks(“TestTable”).Text = String.Empty
doc.SaveToPdf(Server.MapPath(“Table Test.pdf”))
End Sub
Private Sub WriteCell(ByRef currentBuilder As DocumentBuilder, ByVal width As Double, ByVal cellText As String)
currentBuilder.InsertCell()
currentBuilder.CellFormat.Width = ConvertUtil.InchToPoint(width)
currentBuilder.Write(cellText)
End Sub
End Class
Hi
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. Actually, Table cannot be a child of Paragraph. These nodes are always on the same level of nodes hierarchy. If you try to create the expected output in MS Word, you will see this.
Best regards.
Hi, thank you for your quick reply!
Is there some other way to accomplishing this? I have a source DOC which has a table in the numbered list, such as:
A. Some text paragraph
___________________
| | | |
---------------------------------
Some more text paragraphs here
B. Next number.
There are a couple paragraphs, then the table (indented just like the paragraphs are), and then a couple paragraphs below the table, all in the same number (“A” in the example here). How is Word then allowing this to happen?
I am not doing a mail merge because:
1. Will have a variable number of table rows.
2. Will have conditional paragraphs, displayed or not displayed depending on some logic.
Thank you for your help.
Well that didn’t come out right… the original source doc I have, has a table (surrounded by paragraphs) within a numbered list and seems to handle it just fine.
Hi
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for additional information. You are right, the only possible structure is the following:
1. This is the first paragraph
Table after the first paragraph |
|
|
|
|
|
This is the second paragraph
2. And this is the third paragraph
Best regards.