Possible to build up an Excel document programmatically?

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I understand that the new versions of MS
Word, MS Excel etc. allow for creation of
a document using XML tags (the technique
or format is called OOXML, i think).

I imagine that the idea behind such
creation resembles principally the way of
creating a GUI using WPF, where one can
mark up what parts of the text mass
should carry this or that format etc.

Is it at all true? I've been googling and
experimenting a bit lately but i wasn't
especially successfull... :(
 
I understand that the new versions of MS Word, MS Excel etc. allow for
But the format is undoubtedly fairly complex. If you have to create a
document without having Office installed, that might be the only viable
approach. But otherwise, you would probably find yourself better off
actually using Office to create the document, through the Office interop
classes.

The document will be created on a server with no Office
installed (at least not what i can guarantee). The nice part is
that it won't be a very complicated document, most often,
only some data put together, so it won't be that much work.

What i don't really see is how to get started. Suppose i'd like
to create a document with a blue text saying "hello" in cell B3.
How can i do that? I've tried to save sucha document from
Office but i didn't really got an XML-structure in it.

Some pointers or a very short example would be great.
Thanks.
 
K said:
I understand that the new versions of MS Word, MS Excel etc. allow for
creation of a document using XML tags (the technique
or format is called OOXML, i think).

I imagine that the idea behind such creation resembles principally the
way of
creating a GUI using WPF, where one can mark up what parts of the text
mass should carry this or that format etc.
Yes and no. The underlying techniques resemble each other but the formats
really don't. You'd need a serious conversion step to get WPF-to-OOXML.
Is it at all true? I've been googling and
experimenting a bit lately but i wasn't
especially successfull... :(
Producing an Excel document programmatically isn't hard, because, as you've
pointed out, it accepts XML. Actually, Excel even accepts *HTML*, so you can
use a GridView with adjusted rendering to produce a quick and dirty Excel
sheet. See http://aspalliance.com/771

This is basically your idea, but using different technologies. It can be
made more complex if you want "true" Excel sheets (with formulas and such)
using a ControlAdapter and knowledge of OOXML, but if you're going this far
you can probably directly output OOXML instead.
 
I understand that the new versions of MS Word, MS
Producing an Excel document programmatically isn't
hard, because, as you've pointed out, it accepts
XML.

Sorry, i was unclear here. I wish to build up a
FORMATTED Excel document (i.e. with colors, formulas
and all this nice stuff). Is it still not hard?
...if you want "true" Excel sheets (with formulas
and such) using a ControlAdapter and knowledge of
OOXML, but if you're going this far you can
probably directly output OOXML instead.

I'm unclear on "outputting OOXML directly". Would
you like to elaborate? I thought i needed to set up
a String object containing a XML that will "tell"
the computer to color this blue, color that red and
use this and that formula here and there...
 
K said:
Sorry, i was unclear here. I wish to build up a FORMATTED Excel document
(i.e. with colors, formulas
and all this nice stuff). Is it still not hard?
This is harder, obviously. Adapting a GridView will get you a table, but
that's about it.
I'm unclear on "outputting OOXML directly". Would
you like to elaborate? I thought i needed to set up
a String object containing a XML that will "tell"
the computer to color this blue, color that red and
use this and that formula here and there...
Yes, that's basically it (though you don't need to go through a string, just
use XmlWriter or XElement). Writing a GridView to a file is a shortcut to
doing this if all you want is a basic table. If you want to build up an
Excel sheet with all the bells and whistles, you'll have to dig into the
OOXML format. You can make your life easier by designing the sheet(s) you
want in Excel first and saving them, so you can adapt the results rather
than generating things from scratch.
 
I'm unclear on "outputting OOXML directly". Would
If you want to build up an Excel sheet with all the
bells and whistles, you'll have to dig into the
OOXML format. You can make your life easier by
designing the sheet(s) you want in Excel first and
saving them, so you can adapt the results rather
than generating things from scratch.

As far i can see i can't save an Excel document as
XML (OOXML, if you like). Am i missing something? I
took that you ment that i should create a document,
save it as OOXML and then end up having a template
on how to design a formatted document. Did i got it
right? If so, how do i get the OOXML-ized Excel file?
 
As far i can see i can't save an Excel document as
Any time you save an Excel document using the native Excel format, that's
exactly what you're doing.


Your questions are really much more appropriate for a newsgroup
specifically about the use of Office and/or Excel.

Briefly: the Office 2007 file format is basically a ZIP file with some XML
files contained within.
<snipping good info>

Great. I think my brains swallowed it now.
Thanks a lot to both of you, guys!
 
Back
Top