Recent

Author Topic: RTF Data Exporter  (Read 6476 times)

InfoMan

  • New Member
  • *
  • Posts: 49
RTF Data Exporter
« on: May 01, 2012, 01:50:06 am »
Good Evening!

Lazarus 1.1 (04/21/2012) with FPC 2.6.1 and Windows 7 (32 Bit)

I am trying to export a database to a dbf file RTF (RichText) using the component DBExporter. Gero's report but no information appears there. What is happening? Where can I find information on how to use this component (TRTFExporter)? Have export to CSV without problems but is not working. The report is generated but no data is displayed.

Thanks to all who respond.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: RTF Data Exporter
« Reply #1 on: May 01, 2012, 07:11:47 am »
Ciao Infoman,

You're trying to export to RTF... that is not DBF format though...

Are you saying an RTF file is generated but no information appears? And that you are using the CSV exporter and it works? Or are you using a different methot to export CSV?

IIRC, for the graphical export components, you must specify which fields you want to export.
See the demos in the Lazarus source directory: <lazarus>\components\dbexport\demo

The source code for the exporter non-visual code is in <FPC>\packages\fcl-db\src\export

You can find a non-GUI sample that shows how to export to DBF (using a similar approach as RTF export):
http://bugs.freepascal.org/view.php?id=20163
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

InfoMan

  • New Member
  • *
  • Posts: 49
Re: RTF Data Exporter
« Reply #2 on: May 01, 2012, 04:55:00 pm »
Let me explain.

Use a component TDbf to access the data you need to export. I also use various componetes CSV Exporter to export to CSV from the data read from the DBF. This works perfectly.

I tried the same thing using the component RTF Exporter to generate an RTF file, using basically the same code used to generate the CSV.

In both cases (and CSVExporter RTFExporter) I specified all the fields you want to export the same way. The CSV file is generated correctly, and when opened in Excel or Calc it shows the data correctly. The same does not happen with RTF. If the report for example, gives 03 pages it generates three blank pages but no data of any record appears.

Have we looked at the suggested but did not help me much.

Where am I wrong? Thank you for your attention.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: RTF Data Exporter
« Reply #3 on: May 01, 2012, 06:03:35 pm »
Ok, sounds like you're doing things the way they should be done.

If you can write a simple application (perhaps based on one of the demos) that shows the problem with exporting to RTF, perhaps somebody can help... or it can go to the bug tracker as an issue to be fixed...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

InfoMan

  • New Member
  • *
  • Posts: 49
Re: RTF Data Exporter
« Reply #4 on: May 01, 2012, 09:46:27 pm »
No need to develop a project. Compile the project which is in simpledata lazarus demos and generate the executable from it. Attached are the results generated for export to CSV and RTF files from this demo on my computer with Lazarus 1.1 (04.26.2012), FPC 2.6.1 and Windows 7 (32 Bit). I also added the file and the file testdata.dbf MDX (index it) so they can reproduce the test.

Take the quiz and see. Open the file and send testdata.dbf export to CSV. Open the file in Excel or Calc and see the data exported correctly there. Now repeat the process, but have to export to RTF. Open the file and you will see that the data were not exported. I thought it was something wrong with my version of Lazarus but whether it works with the CSV export should work also for export to RTF, right?

The problem occurs with any use which DBF files. Tested multiple files and in all cases was the same result.

How do I fix this? Thank you.

maurog

  • Jr. Member
  • **
  • Posts: 84
Re: RTF Data Exporter
« Reply #5 on: September 08, 2025, 04:31:24 pm »
Hi,

The problem still persists. The RTF file is generated, and while AbiWord can open it without any issues, LibreOffice loads the file without any error messages but only displays blank pages. The screenshot I am posting now shows Infoman’s attachment in AbiWord.

Regards,
Maurog.
And yes, Lazarus is definitely a beast – it comes with everything you need, but sometimes also more than you expect. 😅 (Chat-GPT)

Thaddy

  • Hero Member
  • *****
  • Posts: 19147
  • Glad to be alive.
Re: RTF Data Exporter
« Reply #6 on: September 08, 2025, 05:15:27 pm »
Use a font that is actually on your machine or embed the font as a resource.
This has been solved 13 years ago, so why would itt give you problems now?
No font, no display. Obviously.
« Last Edit: September 08, 2025, 05:17:58 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

wp

  • Hero Member
  • *****
  • Posts: 13512
Re: RTF Data Exporter
« Reply #7 on: September 08, 2025, 06:30:57 pm »
I can confirm that, on Windows, LibreOffice displays a blank page for the InfoMan's file. When I load it in Word there is only a narrow stripe of characters at the left side. This gives the idea to look at the column widths, and I can see that there is no column width info in the file. Following http://www.pindari.com/rtf3.html I added \cellxNUMBER instructions (where NUMBER is the start of a column in twips, 1/20pt), and now the file is displayed correctly in both LibreOffice and Word (well... Word does not display the cell borders, maybe a different story)

Code: Text  [Select][+][-]
  1. {\rtf1
  2. {\fonttbl
  3. {\f0\fswiss Helvetica{\*\falt Arial};}
  4. {\f1\fmodern Courier{\*\falt Courier New};}
  5. {\f2\froman Times{\*\falt Times New Roman};}
  6. }{\stylesheet
  7. {\s1\li0\fi0\ql\sb240\sa60\keepn\f2\b\fs32 Section Title;}
  8. {\s2\ql\sb30\sa30\keepn\b0\i0\scaps1\f1\fs28 Table Title;}
  9. {\s3\li0\fi0\qc\sb240\sa60\keepn\f2\b\scaps1\fs28 Listing Title;}
  10. {\s4\li30\fi30\ql\f2\fs24 Listing Contents;}
  11. {\s5\li0\fi0\ql\sb240\sa60\keepn\f2\b\fs40 Chapter;}
  12. {\s6\li0\fi0\ql\sb240\sa60\keepn\f2\b\fs32 Section;}
  13. {\s7\li0\fi0\ql\sb240\sa60\keepn\f2\b\fs28 Subsection;}
  14. {\s8\li0\fi0\ql\sb240\sa60\keepn\f2\b\fs24 Subsubsection;}
  15. {\s9\li30\fi10\ql\sb60\keepn\f2\fs24 Description titles;}
  16. {\s10\li30\fi30\ql\fs24 Description;}
  17. {\s11\li0\fi0\ql\fs24 Source Example;}
  18. }
  19. \par{
  20. {\b\trowd
  21. \trbrdrh\brdrs\trbrdrv\brdrs
  22. \cellx1200
  23. \cellx2400
  24. \cellx3600
  25. \cellx4800
  26. \cellx6000
  27. \cellx7200
  28. \cellx8400
  29. \cellx9600
  30. \pard\intbl TRACKID\cell
  31. \pard\intbl PERSONID\cell
  32. \pard\intbl FIRSTNAME\cell
  33. \pard\intbl LASTNAME\cell
  34. \pard\intbl DAYOFWEEK\cell
  35. \pard\intbl DATE\cell
  36. \pard\intbl TIMEIN\cell
  37. \pard\intbl TIMEOUT\cell
  38. \row}
  39. }
  40. }

Is there a "default colwidth" command in rtf?
« Last Edit: September 08, 2025, 07:25:38 pm by wp »

wp

  • Hero Member
  • *****
  • Posts: 13512
Re: RTF Data Exporter
« Reply #8 on: September 09, 2025, 12:16:20 am »
Spent some more time with this issue: Installed WordPad in Win11 (they got rid of it some time ago...), it opens the test file without any issues (it does not fit nicely on the page, though). Installed KControls and checked TKMemo - the kmemoeditor_demo displays the test file also, here with relative column widths.

I think the inability of Libreoffice Writer and Word to display the file correctly is an issue of these applications (or intentional - who knows?). I would not spent much time in fixing around the issues of other programs.

Is is absolutely necessary that you export to rtf? You could try to export to Excel (xls, xlsx) or LibreOffice Calc (ods) by using the fpspreadsheet library which you can install from OPM. There is also a dedicated exporter to spreadsheets, similar to the rtf exporter (https://wiki.lazarus.freepascal.org/FPSpreadsheet#Dataset_export)-

Thaddy

  • Hero Member
  • *****
  • Posts: 19147
  • Glad to be alive.
Re: RTF Data Exporter
« Reply #9 on: September 09, 2025, 06:38:28 am »
If you are on windows, you can still use the converters that belong to the RICHEDIT2 (or 5) control and also the Text Object Model (TOM) COM interfaces from the richedit. (Not the lazarus control, but the winapi RICHEDIT2 or higher)
I wrote Delphi converters around 2004-5 for KOL. See if I can find them.
« Last Edit: September 09, 2025, 06:40:38 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

maurog

  • Jr. Member
  • **
  • Posts: 84
Re: RTF Data Exporter
« Reply #10 on: September 09, 2025, 08:34:53 am »
Hi,

I personally do not need the RTF export myself.
At the moment I am trying to revive TurboBird (a Firebird admin tool),
(https://github.com/mdadali/TurboBird)
and a user from the Firebird forum asked me about the RTF export.

It would be nice if the dbExport library could be fixed directly,
instead of relying on workarounds or post-processing the generated RTF files.
Modifying the library locally would not be a clean solution,
since the change would only exist on my machine.

Regards, 
Maurog
And yes, Lazarus is definitely a beast – it comes with everything you need, but sometimes also more than you expect. 😅 (Chat-GPT)

 

TinyPortal © 2005-2018