DocX table empty cells get wrong style

General TRichView support forum. Please post your questions here
Post Reply
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

DocX table empty cells get wrong style

Post by a.weber »

Hello Sergey,
loading a docx (maybe rtf too?) with a complex table results in empty cell's assigned a default style - but in the original document these cells have a assigned style with different font and small size. The wrong font / style changes the height of the row - thats the real problem / bug.

In the load process the table cells are dynamicly splitted and merged as needed - but in case of empty cells this doesn't happen properly so that a default style stays assigned.

So please have a look into RVTable.pas and TRVTableRows.Do_MergeCells( )
- Victim.HasData(False) does only copy the content of the Cell Victim if its content is <>"" but a assigned style is also some content - so I changed
the if from:

Code: Select all

if Victim.HasData(False) then
to

Code: Select all

if Victim.HasData(False) or (Vampire.IsEmpty and Victim.HasData(true)) then
to fix it?

Thanks
André
Attachments
RichView saved DOCX opened with Word.
RichView saved DOCX opened with Word.
richview.png (56.41 KiB) Viewed 121887 times
richview.docx
(4.75 KiB) Downloaded 3678 times
Original DOCX in Word.
Original DOCX in Word.
original.png (56.7 KiB) Viewed 121887 times
original.docx
(21.62 KiB) Downloaded 3693 times
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: DocX table empty cells get wrong style

Post by Sergey Tkachenko »

I changed

Code: Select all

        if Victim.HasData(False) then
to

Code: Select all

        if Victim.HasData(Vampire.ItemCount = 0) then
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

Re: DocX table empty cells get wrong style

Post by a.weber »

Looks too easy and simple... :?:

But Vampire.ItemCount = 0 is not the same as Vampire.IsEmpty() - does that really work? / give the same result?

Or do I miss something?

Code: Select all

if Victim.HasData(Vampire.IsEmpty) then
vs.

Code: Select all

if Victim.HasData(Vampire.ItemCount = 0) then
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: DocX table empty cells get wrong style

Post by Sergey Tkachenko »

I changed your Vampire.IsEmpty to Vampire.ItemCount = 0, so this change affects loading from DocX, but does not affect cell merging initiated by the user.
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

Re: DocX table empty cells get wrong style

Post by a.weber »

Ok - I understand - the same code is also used for the GUI - I didn't see that.

I think the decision shouldn't be necessary and the loader has to tell the function what is merged in that case - which cell is the existing one that should stay ? (kept) - instead haveing a decision based on the content or not... ?

For the moment I think it works only that way - without changing your API. (may be if you do some refactoring that you remember this posting)
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: DocX table empty cells get wrong style

Post by Sergey Tkachenko »

When merging, the resulting cell contains combined content of non-empty merged cells.
When merging while reading DocX/RTF, only one cell may contain meaningful content (and changed text/paragraph style must be counted as meaningful content).
When merging cells as an operation, empty cells are not counted as meaningful content, even if they have changed text/paragraph style.

So, I think this change is OK.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: DocX table empty cells get wrong style

Post by Sergey Tkachenko »

Fixed in TRichView 22.2
a.weber
Posts: 63
Joined: Wed Mar 02, 2022 7:02 am

Re: DocX table empty cells get wrong style

Post by a.weber »

Ok - tested - works - one point less on the list.
Post Reply