Click here to Skip to main content
15,901,426 members
Articles / Web Development / HTML

Report Generator

Rate me:
Please Sign up or sign in to vote.
4.97/5 (244 votes)
11 Oct 2006Public Domain3 min read 1.7M   69.7K   504   521
A plug-in report generator

Sample Image - ReportCreator.gif

Introduction

Printing is a normal part of most applications, but far too convoluted for many developers. The amount of work necessary to add printing of lists and reports to an application often seems daunting, and there are many pitfalls. Here, I come to the aid, with a package containing a plug-in report generator working with template files, a SDI-demo, a plug-and-play report editor for the template files, as well as a demo of the latter. And documentation! The code is intended either for use as-is in your own applications, or as a CReportEditor as well.

ReportCreator also contains a ruler that can be ripped out and used with other CDiagramEditor-derived works. This is an exercise left to the reader, however.

The documentation contains docs on the package structure.

Using ReportCreator

ReportCreator is an editor for the report generator template files. It's first and foremost a vector editor, letting you draw fields on screen with all the features of CDiagramEditor, such as panning, zoom, multiple selects, and much, much more.

It allows you to work in pixels, centimeters or inches as is befitting for a printer-oriented application. The documentation contains detailed information.

Licenses

If you want to add the package(s) or parts of them into your own code - commercial or not, you are completely free to do so. The code comes with the TISATAAFL-license, There Is Such A Thing As A Free Lunch, and you are free to modify, rewrite, resell or do whatever you feel like with the code. You are explicitly allowed to remove my comments in the source and headers, replacing them with your own. You don't have to acknowledge me, neither in code, nor in documentation or the finished application if you should use the code in a commercial application.

History

6/5/2005

  • Initial version

28/5/2005

First of all, a few bug corrections:

  • Fixed resource leak in CCornerBox::OnPaint in the report creator (alex_br).
  • Fixed silly line-thickness bug in draw object line thickness/brush creation (lordly).

As well as a few others that was removed as a spin-off from other modifications.

There are also quite a few changes:

  • Multi-template reports. A report can be composed from several templates, for example, a title page, several sections and a summary (Carsten Bøgh Poulsen).
  • Dynamic object access. Objects can be accessed at runtime, so attributes can be inspected and modified. Objects can also be added at runtime (Håkan Nilsson).
  • More special markers for fields and cells. [%bold%] and [%italic%] will make the field/cell bold or italic respectively. [%separator%], [%bold-separator%], [%double-separator%] will draw a thin line, a thick line or a double line across a row in a grid instead of data (Carsten Bøgh Poulsen).
  • Images can not only be set from files, but also from HBITMAPs and handles to DIBs (Alex Evans).
  • Templates can not only be added from file, but also with data from a CStringArray, a LPCTSTR, a CFile or even from the application resources (DaberElay, Carsten Bøgh Poulsen).

1/10/2006

This project has been neglected for some time, but now it's time for an update! This time, we have:

  • Returning TRUE from Add when adding data as per documentation
  • Added support for font charset. (Vladimir Svrkota, J Bartkowiak).
  • Added locale-handling (J Bartkowiak).
  • Added [%pagebreak%]-command for grids. This works as the other commands, when putting this text in a cell, the grid will break and continue on the next page. (Charlie Curry, Carsten B Poulsen)
  • Added a function call ReplaceCell to set cell data in a grid. This call replaces the data in a specific cell with new data. (Carsten B Poulsen)

And a big thanks for all the help, feedback and support for this project!

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer (Senior) Abstrakt Mekanik AB
Sweden Sweden
45 years old, married, three kids.

Started with computers more than 20 years ago on a CBM-64.

Read Theoretical Philosophy at the University of Lund.

Working as a C++ consultant developer.

Science-fiction freak. Enjoy vintage punkrock.

Comments and Discussions

 
AnswerRe: How to make the number of line in the Grid increased automatically? Pin
Johan Rosengren14-Jan-07 0:54
Johan Rosengren14-Jan-07 0:54 
GeneralRe: How to make the number of line in the Grid increased automatically? Pin
AndersChen14-Jan-07 3:49
AndersChen14-Jan-07 3:49 
GeneralRe: How to make the number of line in the Grid increased automatically? Pin
Johan Rosengren14-Jan-07 6:33
Johan Rosengren14-Jan-07 6:33 
GeneralRe: How to make the number of line in the Grid increased automatically? Pin
AndersChen15-Jan-07 13:24
AndersChen15-Jan-07 13:24 
GeneralRe: How to make the number of line in the Grid increased automatically? Pin
max07352-Aug-07 22:27
max07352-Aug-07 22:27 
GeneralI love you! Pin
AndersChen21-Jan-07 14:09
AndersChen21-Jan-07 14:09 
GeneralFontsize problem Pin
yokosuna3-Jan-07 22:09
yokosuna3-Jan-07 22:09 
GeneralRe: Fontsize problem Pin
Johan Rosengren5-Jan-07 6:46
Johan Rosengren5-Jan-07 6:46 
Thanks for the feedback!


yokosuna wrote:
I see that you multiply an divide the fontsize by 10.0, for the PDFlib, I had to divide by 11.62 (ap.) to get the same result. Have you any clue why this happens ?


I'm working in 10:ths of typographical points, points which are not the same as pixels (a typographical point is 1/72th of an inch, whereas a pixel is - a pixel. that is, it is not a physical measurement). Perhaps the lib is expecting pixels? Or some other more exotic measurement? CUnitConversion::PointsToPixels is used in the application, which might also mean - if you are using this result, that the lib in fact uses typographical points, while the drawing function will finally use pixels? Most likely the latter is true, and you should try not converting the size with PointsToPixels and then use 10.0.


yokosuna wrote:
Another problem is: How can I place one field more than once ?


For this, you'll have to modify the code. You'll have to, for example, modify CReportGenerator::Add to iterate over the fields rather than finding the desired one directly.

yokosuna wrote:
A suggestion: to be able to use some alternativ renedring system instead of DC, I had to add a new Draw() function in every DrawObject() derived class. This makes it impossible to apply new releases of your library without copy an paste the canges. Instead, how about using something like the bridge pattern to separate the two components.


Although the idea has merits, the purpose of this project/article was to help with printing, as Windows printing is notoriously tricky. That is, your proposal lies outside of the scope of the project target. Feel free to do this yourself, however, it might very well incorporate any changes into the main body of code so further development can benefit from it.

A secondary idea of mine is to write code that is, at least theoretically, possible to read, use and maintain for any deadly human (such as myself). For this reason, I'm hesitant over-complicating or over-engineering the code.
GeneralNice! Pin
Amir Mehrabi-Jorshari29-Dec-06 4:46
Amir Mehrabi-Jorshari29-Dec-06 4:46 
GeneralRe: Nice! Pin
Johan Rosengren29-Dec-06 8:48
Johan Rosengren29-Dec-06 8:48 
GeneralrorVS 2005 problem Pin
AlexEvans13-Dec-06 10:10
AlexEvans13-Dec-06 10:10 
GeneralRe: rorVS 2005 problem Pin
busyman15-Dec-06 1:28
busyman15-Dec-06 1:28 
GeneralRe: rorVS 2005 problem Pin
AlexEvans18-Dec-06 18:29
AlexEvans18-Dec-06 18:29 
GeneralRe: rorVS 2005 problem Pin
blackmint15-Dec-06 3:36
blackmint15-Dec-06 3:36 
GeneralRe: rorVS 2005 problem Pin
Johan Rosengren17-Dec-06 6:26
Johan Rosengren17-Dec-06 6:26 
Questionhow to rotate text Pin
rio175-Dec-06 22:02
rio175-Dec-06 22:02 
AnswerRe: how to rotate text Pin
Johan Rosengren7-Dec-06 6:04
Johan Rosengren7-Dec-06 6:04 
GeneralI Love you! Pin
qingshanyin30-Nov-06 21:51
qingshanyin30-Nov-06 21:51 
GeneralRe: I Love you! Pin
Johan Rosengren1-Dec-06 8:32
Johan Rosengren1-Dec-06 8:32 
GeneralJohan,I love you :D Pin
Xuewu Liu26-Nov-06 15:19
Xuewu Liu26-Nov-06 15:19 
GeneralRe: Johan,I love you :D Pin
Johan Rosengren27-Nov-06 5:58
Johan Rosengren27-Nov-06 5:58 
GeneralLast line on a grid Pin
Paolo Vernazza11-Nov-06 7:18
Paolo Vernazza11-Nov-06 7:18 
GeneralRe: Last line on a grid Pin
Johan Rosengren11-Nov-06 20:41
Johan Rosengren11-Nov-06 20:41 
GeneralPostscript errors Pin
schneespm1-Nov-06 22:56
schneespm1-Nov-06 22:56 
GeneralRe: Postscript errors Pin
Johan Rosengren2-Nov-06 7:27
Johan Rosengren2-Nov-06 7:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.