Spire.DOC NullReference when adding row to table

278 views Asked by At

I'm generating pdf with Spire.Doc (https://ibb.co/6sW9cjk). In different sub that code works nicely, but when copied to another sub (will provide the same functionallity as original one) code breaks.

Simple:

  1. get first row of table
  2. fill cells with data
  3. insert new row
  4. repeat unit there is data

Everything is initialized properly, doc is using existing doc file as template to fill it with data.

Today I noticed that even original code is not working! Same error, NullReferenceException when adding second row to table.

If I do like this:

dri.Cells(0).AddParagraph()
dri.Cells(0).FirstParagraph.Text = itemsInReceiptCount

Code works but data is not in table row but under the table. (https://ibb.co/y06nnpP)

Is there any cool fix? Everything was working fine until (???).

1

There are 1 answers

0
Bartek Ferenc On BEST ANSWER

Well, I figured it out.

Somehow code like I mentioned in question doesnt work, but (!) if I did it like that:

For Each i As TableCell In dri.Cells
   i.AddParagraph()
Next

Code will work, table will generate properly (but without borders - easily fixable), paragraphs can be filled with data, no exceptions or errors.

So, I think if it works, it will stay like this.