You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2022/10/13 07:58:05 UTC

[Bug 66312] New: Inserting paragraph into table from cursor

https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

            Bug ID: 66312
           Summary: Inserting paragraph into table from cursor
           Product: POI
           Version: 5.2.2-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: dev@poi.apache.org
          Reporter: aoellerer@protonmail.com
  Target Milestone: ---

Hello
I am trying to insert a paragraph next to another paragraph (`xwpfParagraph`)
in a table in the following way:


1. `XmlCursor cursor = xwpfParagraph.getCTP().newCursor()`
2. `XWPFParagraph paragraph = document.insertNewParagraph(cursor)`

Expectation:
`paragraph` contains a valid `XWPFParagraph`

Reality:
`paragraph` is `null`

This happens because the `XWPFDocument#insertNewParagraph` function checks the
validity of the cursor (in the `XWPFDocument#isCursorInBody` function) by
asserting that the parent of the `cursor` is the document`s body.
This is not the case in the example above, as the parent is the table, and only
the parent of the table is the document body.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #5 from aoellerer@protonmail.com ---
XWPFDocument:716 the element is unconditionally added to the paragraphs array.
If it should be supported by apache poi, one would probably need to do a check
on the parent type of the cursor to do the insertion correctly e.g. with
`tables.get(x).getRow(x).getCell(x).addParagraph();`
But I think this would probably lead to a stark increase in the search space
and resulting runtime of the algorithm?
Maybe it would be best to just specify in the documentation that only insertion
to a `top-level` paragraph is possible?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #7 from aoellerer@protonmail.com ---
Ok, I will see what I can do, or whether I can find a viable path around it,
thank you!

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #4 from aoellerer@protonmail.com ---
From what I've seen in the patched code, the old paragraph doesn't get
replaced, `document.get....getParagraph(0)` always has the same memory adress

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from PJ Fanning <fa...@yahoo.com> ---
I think this is complete

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
could you write a full reproducible test case?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #3 from PJ Fanning <fa...@yahoo.com> ---
I added r1904563 - the test results are not as expected - I had to modify the
broken test to get it to pass.

Anton - could you debug the new code to see why it replaces the paragraph
instead of adding one?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #2 from aoellerer@protonmail.com ---
Sorry for the delay!
https://github.com/AntonOellerer/test-poi-paragraph-insertion

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 66312] Inserting paragraph into table from cursor

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66312

--- Comment #6 from PJ Fanning <fa...@yahoo.com> ---
Honestly, POI XWPF performance is poor due to the overheads in XMLBeans. I'd
prefer to get the code working than to worry about performance. In theory, the
code can be tuned later - or overloaded methods added (again later) that skip
the search if users feel it is not needed in their use case.

I haven't coded much with the XWPF code base and have little enthusiasm to get
more involved.

If you feel like you can modify the insert to do what you need it to do without
breaking existing tests, then I'd be happy to merge whatever you come up with.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org