Recent

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

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1262
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: 5
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)

jjbazaar

  • Newbie
  • Posts: 1
Re: Adding columns to a Word document table (FPVectorial)
« Reply #17 on: April 30, 2024, 06:36:08 pm »
Here is the sample published project in case anyone has a similar problem.

JD
I know this is old but wanted to say thank you. I need this for a project I'm working on in a time crunch, as most of us do.

FYI, as of this writing, the published example hasn't been updated as far as I can tell.
4/30/24.
jjbazaar

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1262
Re: [SOLVED] Adding columns to a Word document table (FPVectorial)
« Reply #18 on: May 03, 2024, 10:45:51 am »
G'day,

Thanks for the nudge.  Now 5 years on, and I still haven't fixed anything.  But I've now checked, and it looks like someone else has.  Whoever you are, many thanks :-)

This is back:
Code: Pascal  [Select][+][-]
  1. TtvTable.AddColWidth()

This has been implemented
Code: Pascal  [Select][+][-]
  1.   If i >= iStart Then  


I tested with the Trunk version of Lazarus, so I don't know when the fixes were applied. 
Err, and it's not called Trunk anymore, can't remember what git calls it, but either way - latest code.

I then compiled: "B:\Apps\Dev\lazarus_trunk\lazarus\components\fpvectorial\examples\fpvtextwritetest2\fpvtextwritetest2.lpi"
Had to disable the pdf_test define at the top of fpvtextwritetest2.pas to bring in the table code.  But the code worked, and produced a Word Document with tables that I expected. 

I then tried the SimpleTable code on the wiki:  https://wiki.freepascal.org/fpvectorial_-_Text_Document_Support

That also worked.  Table didn't exactly match the screenshot, but close enough.  I suspect the differences are Word 365 x Word 2010 issue. 

Looks like no updates are required on the wiki.  Phew :-)

Many thanks to the community for maintaining this. 
« Last Edit: May 03, 2024, 10:47:30 am 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

 

TinyPortal © 2005-2018