How to figure out if the Paragraph is a cell of a Table?

Hi,
I am using Aspose.words to read the document. I need to figure out if the current paragraph, which I am in, is a Cell of a Table or not. Can you please give me a code or point me to a document that can show me how can I defrienciate between regular text and text in a table?
Here is a blue print what I want to do:

Public Overrides Function VisitParagraphStart(ByVal paragraph As Aspose.Words.Paragraph) As Aspose.Words.VisitorAction
‘Here I need to Know If This Paragraph is a Cell of a Table Or Not…
‘Because I am saving Tables in my VisitTableStart function.
Return VisitorAction.Continue
End Function

Thanks very much in advance!
Jerry

Hi
Thanks for your request. You should check if the Paragragh.ParentNoe is the cell or not. See the following code.

if (paragraph.ParentNode.NodeType == NodeType.Cell)
{
    // do something
}

I hope that it will help you.
Best regards.

1 Like

Hi
Thanks for additional information. The Paragraph.NodeType property always returns Paragraph. You should use paragraph.ParentNode.NodeType.
See the following code. It works fine on my side. This code saves the paragraph into the file if this paragraph is inserted into the table cell.

Public Overrides Function VisitParagraphStart(ByVal paragraph As Aspose.Words.Paragraph) As Aspose.Words.VisitorAction
Dim doc As Aspose.Words.Document = New Aspose.Words.Document("out.doc")
Dim importer As Aspose.Words.NodeImporter = New Aspose.Words.NodeImporter(paragraph.Document, doc, Aspose.Words.ImportFormatMode.KeepSourceFormatting)
If Not paragraph.ParentNode.NodeType = Aspose.Words.NodeType.Cell Then
Dim par As Aspose.Words.Paragraph = importer.ImportNode(paragraph, True)
doc.FirstSection.Body.AppendChild(par)
parNum = parNum + 1
End If
doc.Save("out.doc")
Return Aspose.Words.VisitorAction.Continue
End Function

I hope that it will help you.
Best regards.

Hi
It seems that your problem occurs because some of your table cells contains another tables. Try to use the following code.

Public Overrides Function VisitTableStart(ByVal table As Aspose.Words.Table) As Aspose.Words.VisitorAction
Dim oCommentDoc As Aspose.Words.Document = New Aspose.Words.Document("out1.doc")
Dim oImp As New Aspose.Words.NodeImporter(table.Document, oCommentDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting)
If Not table.ParentNode.NodeType = Aspose.Words.NodeType.Cell Then
Dim oTempTable As Aspose.Words.Table = oImp.ImportNode(table, True)
oCommentDoc.FirstSection.Body.AppendChild(oTempTable)
End If
oCommentDoc.Save("out1.doc")
End Function

I hope that it will help you.
Best regards.

Ye, It worked!
Thanks very much for your help and time.
Jerry