Hallo.
I create 5 same copies of table in document. They create without problem.
For poc = 0To 5
Dim tableAsNewTable(doc.MainDocumentPart.Document.Body.Elements(Of DocumentFormat.OpenXml.Wordprocessing.Table)().ElementAt(0).CloneNode(True))
Dim mainDocumentPartAsMainDocumentPart = doc.MainDocumentPart()
Dim bodyAsBody = mainDocumentPart.Document.AppendChild(NewBody())
Dim paraAsParagraph = body.AppendChild(NewParagraph())
Dim runAsRun = para.AppendChild(NewRun())
run.AppendChild(table)
'run.AppendChild(New Break())
mainDocumentPart.Document.Save()
Next
The problem start, when i want to write text to table.
For poc = 0To 6
Dim tableAsTable
Dim rowAsTableRow
Dim cellAsTableCell
Dim pAsParagraph
Dim rAsRun
Dim tAsText
table = doc.MainDocumentPart.Document.Body.Elements(OfTable)().ElementAt(poc)'it show me error here, during second cycle!!!
row = table.Elements(OfTableRow)().ElementAt(1)
cell = row.Elements(OfTableCell)().ElementAt(0)
p = cell.Elements(OfParagraph)().First()
r = p.Elements(OfRun)().First()
t = r.Elements(OfText)().First()
t.Text = poc & "XYZ"
Next
Text write only in to table, that was already in document. I use this table as template.
When i write text to first created table, this table shows error.
table = doc.MainDocumentPart.Document.Body.Elements(OfTable)().ElementAt(poc)
Additional information: Specified argument was out of the range of valid values.
It looks to me, as if it can't find these new tables for writing text. What i am doing wrong during creating tables? When i manualy coppy tables to document, it write text to it correctly. Problem is only when i create them through my code .
Thank you for your answer.