custom reports - negative numbers in red

Lt. Goose ltgoose at gmail.com
Mon Apr 15 13:13:12 EDT 2013


Hi all,

I've fiddled a bit more with html-styles and style-sheets, but I'm getting
stuck trying to add a style to the html-document style-sheet. I've been
able to display negative amounts in red (as easy as using the right class
type that can be seen in stylesheet-plain.scm , for instance). I finally
used "number-cell-neg" with the default gnc:make-html-table-cell/markup and
I got the result I expected.

However, if I try to add a new style to the style-sheet, it never gets
rendered into the final report (when exporting the html report, the new
style is nowhere to be seen). I suppose that the style-sheet is loaded
after the report is rendered, overriding any style set and making it
useless to add it in the report renderer.

I'd like to display columns alternating background color (in the same
fashion as it is done with rows). In order to do that easier, I'd like to
add two new styles to the document's style-sheet. What I've been trying to
add is something like this for each style:

      (gnc:html-document-set-style-text!
          document
          (string-append
              "td.alt-col-number-cell { background: gray }\n" ))

to no avail, because the style td.alt-col-number-cell does not appear in
the final html document.

I've managed to render the actual td data with the right class values,
using this:
              (gnc:html-document-set-style!
                 document "alt-col-number-cell"
                 'tag       "td"
                 'attribute (list "class" "number-cell alt-col"))

and then rendering the value in a cell with
(gnc:make-html-table-cell/markup "alt-col-number-cell" ...)


So, does somebody know if there is a way to add a new style to the
style-sheet inside the report renderer? I think I could modify the
stylesheet-plain.scm or the fancy or any of the other scm files, but it
would be much cleaner if I could do it inside the report code. And of
course, I'd rather do it using CSS instead of using plain html-markup codes
inside the report.

Any help or suggestions will be greatly appreciated.

Regards,
Gus.

2013/4/5 Carsten Rinke <carsten.rinke at gmx.de>

> Hi Gus,
>
> sorry to say, but I think I cannot help you with the style sheets as I did
> not explore them yet.
> I am still stuck with writing the clumsy scheme phrases ;-)
>
> Once that you find a good way forward, please document your experiences in
> http://wiki.gnucash.org/wiki/**Custom_Reports<http://wiki.gnucash.org/wiki/Custom_Reports>
> (and I'd appreciate if you sent an update notification to this list after
> that)
>
> Kind regards,
> Carsten
>
>
>
> On 04/04/2013 06:35 PM, Lt. Goose wrote:
>
>> Thanks for your help, Carsten.
>> I was able to display red text for negative amounts (they came from a
>> commodity-collector, by the way). However, though the result displays
>> right, the generated html overhead can be a bit heavy (depending on the
>> time-interval and the number of accounts, and the scheme code turns even
>> more unreadable ;-) ). I tried with something like this, changing the value
>> to a formatted html-text:
>>
>> (gnc:make-html-table-cell/**markup "number-cell" (gnc:make-html-text
>> (gnc:html-markup "b" (gnc:html-markup "font color=red"
>> (gnc:make-gnc-monetary (gnc-default-currency) act-bal))))))
>>
>> Of course, using html-text and html-markup, I can render almost any html
>> code (I'm still struggling to change the background color of a cell),
>> though it would be nicer if I could just use something like the
>> "number-cell" markup used for the whole cell (the <td> tag) and let the CSS
>> stylesheet do the formatting. In other words, is it possible to dynamically
>> modify/add styles to the report stylesheet (I mean within the report
>> options or report code, for example)?
>>
>> I'd rather include something like this in the report (this is taken from
>> the html-exported report):
>>
>> <style type="text/css">
>> td.number-cell { font-family: Segoe UI; font-size: 10pt;  }
>> td.number-header { text-align: right; font-family: Segoe UI; font-size:
>> 10pt;  }
>> td.neg { color: red;  }
>> </style>
>>
>> For example, adding a new style for cells:
>> td.neg-number-cell { font-family: Segoe UI; font-size: 10pt; color: red }
>>
>> Is there a way to define such a style? Some kind of gnc:make-html-style
>> interface?
>>
>> Also, notice the "td.neg" style defined in the stylesheet, that I haven't
>> been able to use. How should I do it?
>>
>> Thanks again in advance for your comments.
>> Gus.
>>
>>
>> 2013/4/3 Carsten Rinke <carsten.rinke at gmx.de <mailto:carsten.rinke at gmx.de
>> >>
>>
>>
>>     Hi Gus,
>>
>>     for text I would start playing around with something like this:
>>
>>              (gnc:make-html-text
>>                (gnc:html-markup "color=red" "negative amount")
>>              )
>>
>>     or similar (not sure about the font color commands in HTML).
>>
>>     If this works for tables I don't know.
>>
>>     What is the HTML code that you want to achieve?
>>
>>     Kind regards,
>>     Carsten
>>
>>
>>
>>     On 04/02/2013 06:06 PM, Lt. Goose wrote:
>>
>>         Hi all,
>>         I've been using gnucash for some months and lately I've been
>>         trying to
>>         create my own reports (learning a bit of scheme in the
>>         meantime). I've
>>         managed to render a table with the data I need (some kind of
>>         cash-flow
>>         report that reports several accounts in columns, sorted by the
>>         date where
>>         at least one transaction took place - so that you know your
>>         total balance
>>         change everyday any transaction happened). I've got it running
>>         now after
>>         some investigation.
>>
>>         Anyhow, what I'm trying to do now is to format the output in a
>>         fancier way,
>>         but I cannot find the way to format a html-cell with a
>>         negative number
>>         (using the option to display negative numbers in red). For
>>         instance, I'm
>>         writing this and I'm getting a normal cell:
>>
>>               (total-value (gnc:make-html-table-cell/**markup
>>         "total-number-cell" (car
>>         value)))
>>
>>         I've tried other markup texts like "neg-total-number-cell" or
>>         simply "neg"
>>         but to no avail. Does anybody know how to format this?
>>
>>         And it'd be fantastic to have a reference of predefined markup
>>         texts that
>>         are configured in the style sheets.
>>
>>         Thanks in advance.
>>
>>         Gus.
>>         ______________________________**_________________
>>         gnucash-user mailing list
>>         gnucash-user at gnucash.org <mailto:gnucash-user at gnucash.**org<gnucash-user at gnucash.org>
>> >
>>
>>         https://lists.gnucash.org/**mailman/listinfo/gnucash-user<https://lists.gnucash.org/mailman/listinfo/gnucash-user>
>>         -----
>>         Please remember to CC this list on all your replies.
>>         You can do this by using Reply-To-List or Reply-All.
>>
>>
>>
>>
>


More information about the gnucash-user mailing list