Spreadsheet exporting?

Christopher Browne cbbrowne@hex.net
Fri, 25 Aug 2000 22:34:00 -0500


On Fri, 25 Aug 2000 17:50:54 PDT, the world broke into rejoicing as
Dave Peticolas <peticola@krondo.com>  said:
> Matthew Vanecek writes:
> > Are there any plans to support importing/exporting from/to any
> > spreadsheet formats, or even to csv?  It would be handy to have that,
> > both on the accounts, and on the reports.
> 
> There is some scheme code in src/scm/gnumeric that Christopher
> Browne wrote for generating gnumeric xml data, but it hasn't
> been hooked into GnuCash yet, afaik.

Indeed.

I've been plugging away bit by bit at getting code that directly generates
HTML pulled _out_ of the reports; that's a first step towards untying
the dependancy on HTML.

(I "did" one report today; I'll have to validate the results before
pushing it into CVS.)

What that does is that reports won't directly create any tags, ala
 (string-append "<TR> <TD>" value </TD> </TR>"), but will instead
use something like:
 (html-table-column value)
which will generate the equivalent.

The NEXT step is then to replace all (html-[whateverfunction]) references
with just straight ([whateverfunction]).

The step after that is to build some sort of dispatcher whereby one would
generate sets of "methods."  Thus, you'd have definitions like:

(define (html-do-this args)
  (whatever))

(define (html-do-that args)
  (whatever))

(define (html-something-else args)
  (whatever))

(define (gnumeric-do-this args)
  (whatever))

(define (gnumeric-do-that args)
  (whatever))

(define (gnumeric-something-else args)
  (whatever))

And then throw all the methods into a set of association tables:

(define html-list
   '((do-this . html-do-this) (do-that . html-do-that) 
     (something-else . html-something-else)))

(define gnumeric-list
   '((do-this . gnumeric-do-this) (do-that . gnumeric-do-that) 
     (something-else . gnumeric-something-else)))

And then [do some magic] so that the reports look up the appropriate
functions from html-list or gnumeric-list to do their things.

By the way, I may have the steps a bit backwards.

The other piece of the approach that might prove worthwhile would be
for the report programs to just generate "trees," rather like:

(report ((title . "My Report"))
  (table
    (header 
     (row
      (column "Description") (column "Amount")))
    (body
     (row
      (column "Salary") (column 500))
     (row
      (column "Interest") (column 20.15))
     (row total
      (column "Total Income") (column 520.15))
     (row
      (column "Rent") (column 275.15))
     (row
      (column "Food") (column 70.15))
     (row
      (column "Car") (column 220.15))
     (row total
      (column "Total Expenses") (column 565.45))
     (row grandtotal
      (column "Net loss") (column 45.30)))))

And then push that tree at a "renderer" that would do meaningful things
to a row, column, header, body, and table.

Note that this may be trivially rendered into XML, thus satisfying the
daily requirements for buzzwords, and may be serialized to disk if
archival be required.

Note that my "vision" here is for this all to provide a generic sort of
interface that _all_ reports may make use of.  That won't happen
tomorrow, but I'll certainly endeavor to keep things working as it
evolves.

If someone wants to do a _specific_ dump of data to Gnumeric, in XML
form, the source code already in the tree provides a simple demonstration
of how to create a valid Gnumeric data file, and it would be quite 
reasonable to make a special-purpose Guile script to generate that.
--
aa454@freenet.carleton.ca - <http://www.ntlug.org/~cbbrowne/spreadsheets.html>
Academics denigrating "Popularizers"

"During the rise of the merchant class, the landed aristocracy
understood the value of creating food, but didn't appreciate that food
isn't valuable unless it reaches hungry mouths.

New ideas aren't valuable unless they reach hungry minds. "
-- Mark Miller