Recent

Author Topic: [SOLVED] Adding columns to a Word document table (FPVectorial)  (Read 1355 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1250
Re: [SOLVED] Adding columns to a Word document table (FPVectorial)
« Reply #15 on: October 24, 2019, 09:05:58 pm »
G'day,

Heh.  I've only been offshore twice this year, and both times bugs in my code have been found.

Apologies @JD, when I got back onshore I completely forgot to follow up and get the trunk code fixed.  And I see CellSpacing has now failed


Quote
As i tested, every single char such as 'A', 'B', or '1', '2'... will be empty in saved docx or odt file

@qindj
Right - I've confirmed that indeed there is a bug.  I'll get to it, but in the meantime you're going to need to keep appending those spaces. 

I'm away from IDE at the moment (Yes, offshore again working 12 hours shifts).

The following are my quick notes to assist with chasing this when I have time.   I'm planned to be back on shore Nov 4, so I should reply sometime in the weekend following that.  If you haven't heard, ping me (pm or here) and remind me.

The issue is likely in docxvectorialwriter.pas,

Line 703.  For some reason AddTextRun doesn't look like it's being run (in the xml of the resulting word document, not only is the there no text, but there's no w:r tag written either, and that's done in AddtextRun).  Oh, or AddTextRun  is being passed an empty string.  Ah, that's makes more sense.  If it's being passed with an empty string, then the following code needs to be tightened to ONLY strip CR or LF. 

Line 696:
Code: Pascal  [Select]
  1.         // Strip out the trailing line break
  2.         // added by TStringList.Text
  3.         If DefaultTextLineBreakStyle = tlbsCRLF Then
  4.           sTemp := Copy(sTemp, 1, Length(sTemp) - 2)
  5.         Else
  6.           sTemp := Copy(sTemp, 1, Length(sTemp) - 1);  

If my suspicion is right about that code being overzealous and stripping two chars when there is only one to be stripped, then I'd expect missing characters all over the place.  Replacement code for the above should be TrimChars(<string>, [CR, LF]).  There will be one floating around somewhere.  Not sure, but have to resume work now :-(

Cheers

Mike

UPDATE:   OK, I've broken out an IDE.  No, it wasn't the above code.

Issue is actually in AddTextRun.  I'm parsing over the passed string - looking for internal LF, CR, TAB, so I can turn large collections of text in to actual word paragraphs.

Except, I start my looking at the wrong index :-(

Quick fix:
Line 554 of docxvectorialwriter.pas needs to be changed to:
Code: Pascal  [Select]
  1.           If i >= iStart Then    
(it was previously i > iStart, so worked for strings with length > 1)

Better fix:
Mike remembers this time and supplies an actual patch, fixing both this and @JD's issue.


« Last Edit: October 24, 2019, 10:31:07 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Dean Qin

  • Newbie
  • Posts: 3
Re: [SOLVED] Adding columns to a Word document table (FPVectorial)
« Reply #16 on: October 25, 2019, 08:05:56 am »
@Mike

Thank you for your time & explaination, I use the fix you suggested and It works now (Single char without space)