Forum > FPvectorial
[SOLVED] Adding columns to a Word document table (FPVectorial)
Mike.Cornflake:
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
--- End quote ---
@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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- // Strip out the trailing line break // added by TStringList.Text If DefaultTextLineBreakStyle = tlbsCRLF Then sTemp := Copy(sTemp, 1, Length(sTemp) - 2) Else 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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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.
Dean Qin:
@Mike
Thank you for your time & explaination, I use the fix you suggested and It works now (Single char without space)
jjbazaar:
--- Quote from: JD on April 17, 2019, 04:20:20 pm ---Here is the sample published project in case anyone has a similar problem.
JD
--- End quote ---
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:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TtvTable.AddColWidth()
This has been implemented
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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.
Navigation
[0] Message Index
[*] Previous page