US and Worldwide: +1 (866) 660-7555
+ Reply to Thread
Results 1 to 8 of 8

Thread: Tips for generating Excel reports?

  1. #1

    Default Tips for generating Excel reports?

    Hi all,
    I'm asking the community if there are any tips on using JFreeReport when trying to generate XLS/excel reports cleanly (based on 0.8.X series).

    For example,
    *avoiding 'layout' cells that do not need to be there.
    *cell borders (line or rectangle object?).
    *overlap-issues (if one label/field is touching/overlapping another, the '2nd' will not show up in the XLS at all).

    One tip I can share is that lines can not start at X position '0', it must be '0.1' or will not render.

    Edit: usecase is for re-creating existing Excel reports, so the more exact the better :-)

    thanky,
    -D
    Last edited by dhartford; 02-09-2007 at 10:26 AM.

  2. #2

    Post

    I've found couple of hints:

    *Use line objects to draw cell borders. Swap between vertical and horizontal lines.

    *Esablish the line object directly on the 'left' side of field/label objects. Do not overlap field/label on the right side/width (i.e. 119.9 instead of exactly 120 widths to avoid overlaps). Left margin for both horizontal and vertical lines start at 0.1, not 0.0, otherwise will not render. Note that this will cause a 'mini' column A, but does not seem to be a work around.

    *Top line objects can also be directly on the 'top' of field/label objects.

    *The far-right margin lines do render (even at the exact end), but the XLS export seems to add an extra 'mini' column making it not clear that it was rendered properly.

    *Page formatting (A4, letter, legal, landscape) and rotation (portrait/landscape) are not carried over as defaults, so 'print' will always print portrait letter (or, I'm assuming, A4 based on region) at least in preview mode - more testing in production/deployment needed to verify whether this is a preview-only bug in the Designer, or an XLS export bug.

    *Page layout/sizing during design does not seem to be respected in the XLS export (i.e. print preview is very different in Excel then what is visible in the designer). Cell/Column widths with regards to relative page location in the Designer does not match in XLS export. What this means is although you designed for portrait or landscape width, the actual Excel print preview will span multiple pages because the width is not the same.

    Tested using the Report Designer 1.2.0-RC1.
    Last edited by dhartford; 02-09-2007 at 10:33 AM.

  3. #3

    Default

    Feature not available in the Designer (would be good to add to Report properties):

    Excel gridline (Excel Page Setup->sheet->gridline) toggle:
    http://forums.pentaho.org/showthread.php?t=42455

  4. #4

    Default

    Bottom borders for cells are nigh impossible. The only solution I have found is to draw a line where you normally would want to, then assuming there are no other elements below where you want the line, draw ANOTHER line below it (2 lines as the only items in the bottom of the band). Removing one or the other will cause non-render problems in Excel/XLS export, but leaving as-is would render double-lines in all other formats.

    edit: I was trying to add a bottom border in the Report Footer band, with no Page Footer data. This was causing the above problem. When I added objects to the Page Footer band, suddenly everything was working correctly in the Report Footer band/bottom border of a cell. Wierd bug :-P
    Last edited by dhartford; 02-12-2007 at 11:32 AM.

  5. #5

    Default

    Missing feature - padding

    Being able to handle padding on field and labels would greatly improve compatibility of both PDF reports and Excel XLS reports. Moving fields/labels for proper location on a PDF report would cause extra layout cells in an XLS export, while optimizing for XLS export causes bunching in the PDF export (i.e. the information in a field/label would be right beside a line, when there should be 'padding').

    line with a field beside it:

    |data start

    versus with padding:

    | data start

    But the padding would still export to XLS without excess layout cells.

  6. #6
    Join Date
    Mar 2003
    Posts
    5,974

    Default

    Hi,

    *avoiding 'layout' cells that do not need to be there.
    *cell borders (line or rectangle object?).
    *overlap-issues (if one label/field is touching/overlapping another, the '2nd' will not show up in the XLS at all).
    [quote]
    One tip I can share is that lines can not start at X position '0', it must be '0.1' or will not render.
    [/qoute]

    Using a manual definition in XML (the only way to prove that the engine messed up and not one of the GUI tools ) I had no problems adding a horizontal or vertical line at (x=0, y=0). But I encountered problems adding a vertical line at the *end* of the band (at x=100%, there is no such representation in the designer) - such lines got ignored.

    Tracker for that:
    http://sourceforge.net/tracker/index...69&atid=464140

    *Esablish the line object directly on the 'left' side of field/label objects. Do not overlap field/label on the right side/width (i.e. 119.9 instead of exactly 120 widths to avoid overlaps). Left margin for both horizontal and vertical lines start at 0.1, not 0.0, otherwise will not render. Note that this will cause a 'mini' column A, but does not seem to be a work around.
    and

    If the line itself covers *exactly* the bounds of the text-element, it will export correctly without any extra spaces.

    Example (Using the Simple-XML format
    Code:
    <band>
      <line name="top" x1="10" y1="10" x2="110" y2="10"/>
      <line name="bottom" x1="10" y1="30" x2="110" y2="30"/>
      <line name="left" x1="10" y1="10" x2="10" y2="30"/>
      <line name="right" x1="110" y1="10" x2="110" y2="30"/>
      <label x="10" y="10" width="100" height="20">Test</label>
    </band>
    However, you may run into a Report Designer specific issue here, as the report designer uses a different text-height algorithm than the ordinary reporting engine. A font with height 14 usually has a slightly larger effective size as there is some extra space reserved for accents and other extra-stuff. So such an text-element easily gets a height of 16 or more (depends on the font). One solution would be to place the line slightly below the text element - in the default mode the Excel exporter will then increase the height of the text element to the next line (or any other break).

    Bottom borders for cells are nigh impossible. The only solution I have found is to draw a line where you normally would want to, then assuming there are no other elements below where you want the line, draw ANOTHER line below it (2 lines as the only items in the bottom of the band). Removing one or the other will cause non-render problems in Excel/XLS export, but leaving as-is would render double-lines in all other formats.
    Bug of the engine. Here's the tracker:
    http://sourceforge.net/tracker/index...69&atid=464140

    Page layout/sizing during design does not seem to be respected in the XLS export (i.e. print preview is very different in Excel then what is visible in the designer). Cell/Column widths with regards to relative page location in the Designer does not match in XLS export. What this means is although you designed for portrait or landscape width, the actual Excel print preview will span multiple pages because the width is not the same.
    The text and cell sizing is a dark chapter. In a dark and moonless night, the very first Excel developer went out into the woods to worship some ancient daemons. Armed with a half-rotten book on C programming (written on the skin of slain FORTRAN programmers with the blood of COBOL developers by an occult sect using an forgotten magical language called LISP) he summoned the most evil daemons (no, not Bill Gates, he's not that bad after all) and asked how to make this world as misserable as he felt that day. (When you feel bad, there's nothing better than sharing your pain with the world.)

    Two days later he finished the first specification on how Excel will store cell sizes.

    Excel stores the cell width in an abstract measurement, which is based on the width of the character 'm' of the first font that is declared in the workbook. The height of a cell is specified in points (some sort of). Every system has its own way to measure font sizes. Your JDK happily assumes font sizes based on what the font renderer backend tells it. A font height, however is not just Ascend + Descend - it is also based on the maximum glyph size and a lot of other things (for instance how the font-backend interprets all the funny numbers inside the *.ttf file). So most of the time, fonts are very plattform dependent. In JFreeReport, measuring the cell height is some sort of guessing - we try to use some magic calculations to get a result that has a high probability to look good on most systems.

    There is no way, how anybody can know, how Excel will render a workbook. The only sane way would be to use Excel itself to compute the cell sizes - but that functionality is not exposed (even if you dare to start coding a COM+ component to access the Excel object).

    Missing feature - padding
    http://jira.pentaho.org:8080/browse/REPORTING-216


    (And at some point it would be wise to tell more about the way the excel exports work. In the next posting ...)

    Have fun,
    said Thomas

  7. #7

    Default

    lol, thank you for the humorous post Thomas :-)


    Hopefully a number of these items will be addressed in the 0.9 engine/1.6 designer.

    The width problem is interesting - my work-around was to change my default margins to be much larger (somewhere between 80 and 96) instead of the default 20 with regards to Excel width calculations, but the font problem would still exist - but that is something the Report designer/analyst should keep in mind.

  8. #8

    Default

    XLS Header/Footer:

    Presently, 0.8.X series, defining information in the Page Header and Footer sections of the report does not necessarily create header/footers in Excel/XLS. This causes a mis-expectation that a page footer would be at the bottom of the 'page' in Excel, when in fact it will be printed right under the last band (particularly ugly if you have only a couple item bands taking only the top 1/4 of the page with a footer at the 1/2 page mark).

    However, my guess is that this may be challenging from the dynamic content/data element standpoint more so than actual technology. At any rate, something to keep in mind.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts