Re: how to print data with a table-like layout in txt file
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, September 18, 2008, 5:28:53 AM, HawkCoretech wrote: > Hi all, > I would like to print data with a table-like layout in a pure txt file (NOT > in html file), like following: > B01 154 155 140 147 147 149 158 117 149 142 152 147 160 147 > B02 0 0 0 0 1 0 0 0 0 0 0 0 0 0 > B03 0 0 1 0 0 0 0 0 0 0 0 0 0 0 > B04 0 5 2 1 2 1 2 4 2 1 1 4 2 4 > B05 2 1 3 2 2 0 3 9 0 3 0 0 0 2 > B06 1 0 1 2 0 2 0 0 5 2 0 1 0 0 > B07 0 1 1 0 0 2 0 1 0 1 0 0 0 1 > B08 2 1 3 2 0 1 1 0 1 2 2 1 1 2 > > the data comes from database query. > > my idea is : > 1)calculate the data and store them in a sequence row by row, use <#list> > to print it all. > > but if we want this table has more flexibility or configurable, for example > a summary column or summary row like this: > > B01 154 155 140 147 147 149 158 117 149 142 152 147 160 147 > total > B02 0 0 0 0 1 0 0 0 0 0 0 0 0 0 > 1 > B03 0 0 1 0 0 0 0 0 0 0 0 0 0 0 > 0 > B04 0 5 2 1 2 1 2 4 2 1 1 4 2 4 > 29 > B05 2 1 3 2 2 0 3 9 0 3 0 0 0 2 > 27 > B06 1 0 1 2 0 2 0 0 5 2 0 1 0 0 > 16 > B07 0 1 1 0 0 2 0 1 0 1 0 0 0 1 > 7 > B08 2 1 3 2 0 1 1 0 1 2 2 1 1 2 > 19 > total 5 7 11 7 5 6 6 14 8 9 3 6 3 9 > 99 > > or even more complex printing like cross table, or separation line, > adjusting column width, row height, spacing between columns, maybe we should > 2)build a custom data model for table. > > any suggestion? thanks in advance. FreeMarker is not meant to be used for calculation, only for the presentation (visual things) of already existing data, so in principle 2) is the way to go. But some non-MVC application still chooses templates to do calculations, but only trivial ones, primarily because FreeMarker can't really build tables dynamically, unless you create some custom methods (TemplateMethodModelEx) for that, also for more complex algorithms its syntax is too verbose. Regarding adjusting column width and like, that's the task of the template, you should do it there. Although, frankly, I'm not too optimistic regrading the plain-text formatting capabilities of FreeMarker or of any other "Web" template engine, as these things are designed for printing white-space insensitive things, like HTML. (Besides, generating plain text on-the-fly on the manner as HTML is generated in these template engines is just impossible in the generic case. Even if a plain text specialist template engine was exist, it certainly would want you to enter some XML-ish thing into the template (not the plain text), that it would render to plain text in bursts at certain points, like even only when the template execution was finished. But, of course formatting tables in a concrete application can be simpler than the generic case.) -- Best regards, Daniel Dekany ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/