Casting Error

Hello,

I am receiving the error:

Unable to cast object of type ‘Aspose.Words.BookmarkStart’ to type ‘Aspose.Words.Tables.Cell’

when trying to see if a cell in a table contains text. I have the following code snippet to provide some context:

doc.UpdateFields()
Dim tables As Node() = doc.GetChildNodes(NodeType.Table, True).ToArray()
Dim table As Tables.Table = DirectCast(tables(0), Tables.Table)
Dim rowToRemove As New ArrayList()

For Each row As Tables.Row In table.Rows
	Dim emptyrow As [Boolean] = True
	For Each cell As Tables.Cell In row
		If cell.GetText.Trim <> "" Then
			emptyrow = False
		End If
	Next

	If emptyrow = True Then
		rowToRemove.Add(row)
	End If
Next

For Each row As Tables.Row In rowToRemove
	If row IsNot Nothing Then
		row.Remove()
	End If
Next

Any ideas why this may be happening? I am using Aspose.Words version 21.2 if that helps in any way.

Thanks,

Trevor

@trevor.karl Could you please attach your problematic document here for testing? We will check the issue and provide you more information.

Here’s my problematic document. Thanks for the quick response!
JETemplate_Ex-Member.docx (29.6 KB)

@trevor.karl Please replace the following line:

For Each cell As Tables.Cell In row

to the following

For Each cell As Tables.Cell In row.Cells
1 Like

@alexey.noskov That actually worked! You’re incredible, sir. Thank you so much for the help, I appreciate it greatly!

1 Like