Sure.

Start with an understanding that an XLS file encoded in an archive 
format much like Zip or Tar, etc.  It contains a tree
of files.  A doc file (for instance) is in the exact SAME format.  Our 
port of this is called POIFS.

One of the files in that archive is called "Workbook" and that is the 
*only* thing that HSSF currently deals with.
When HSSF reads a workbook it reads in only the "Workbook" file from the 
XLS archive, and ignores all other
entries.  So when HSSF writes it back, it writes it back without the 
other files in the XLS archive.

There are most likely other binary records in the "Workbook" file that 
point to the other files in the XLS archive (aka
OLE 2 Compound Document), but HSSF should read them in and write them 
back out roughly where it found them.  
(not true for cellvalue records, which will probably be reordered 
slightly, but this has not been a problem up until now).

To see the structure of the XLS file run 
org.apache.poi.poifs.dev.POIFSViewer (pass it the file).  It should list 
the "directory tree".

To see the structure of the "Workbook" file contained in the XLS archive 
you should use org.apache.poi.hssf.dev.BiffViewer  (pass the file as the 
argument).  If you have Cygwin (www.cygwin.com) or a Unix box then you 
should be able to output two files with a minor
alteration and see the effect on the "Workbook" file by outputting the 
two and running "diff" against them.  (You may be able
to use a GUI diff, but the files can be quite large, so you probably 
only want to see the differences)

So to add Macro capability you need to:
   1. Make HSSF pay attention to the *macro* file in the XLS archive
   2. Make it keep it
   3. Make it rewrite it.
   4. Start here 
http://jakarta.apache.org/poi/javadocs/javasrc/org/apache/poi/hssf/usermodel/HSSFWorkbook_java.html#HSSFWorkbook
 
and look at the  public HSSFWorkbook 
<http://jakarta.apache.org/poi/javadocs/javasrc/org/apache/poi/hssf/usermodel/HSSFWorkbook_java_ref.html#HSSFWorkbook.HSSFWorkbook%28POIFSFileSystem%29>(POIFSFileSystem
 
<http://jakarta.apache.org/poi/javadocs/javasrc/org/apache/poi/poifs/filesystem/POIFSFileSystem_java.html#POIFSFileSystem>
 
fs) method.  Notice how it creates an InputStream from the "Workbook" 
file.  From my understanding a Macro would be stored as another file in 
the OLE 2 Compound Document.  You want that.

So that should give you some understanding.  As you can tell thats not 
too hard.  So why haven't I done it?  Well here are my additional 
requirments for this to make a production release (and it may be a pain 
but I think as a user you'll appreciate why).

1. I should be able to turn it off (conserve memory) if I want. 
 Probably best to leave it on by default.
2. It will need appropriate unit tests.
3. It will need to be properly documented.  (by supplying updates to the 
appropriate documentation)

This information gives you a few options:

1. Wait for me to do this (might be awhile, low priority at the moment)
2. Do this and
     a. keep it to yourself
     b. supply it (as a patch) without the appropriate unit tests/docs 
and hope someone supplies them before POI 2.0 is released.
         (because if not I'll rip it out before release -- sorry)
     c. Supply a complete patch providing the feature, documentation and 
unit tests.  (code complete)  You'll get more credit, it will look
         nice on your resume, and I'll probably even mention you in the 
news blurb for the jakarta homepage.  

Hope this helps.

BTW, if you're interested in adding addional features, in addition to 
the OpenOffice "XLS SPEC" linked from the home page, grab "Microsoft 
Excel 97 Developer's Kit" available used on Amazon for like $15 bucks. 
 It explains the file format more fully than even I have.  With the 
above information, tools, website docs and this book, you'd know 
everything I, Glen, Marc and Avik know about hacking HSSF.

And thats all I have to say about that,

-Andy Gump.

Christian Bourque wrote:

>Hi Andrew !
>
>I'm working on a project where we use Excel files to exchange data with our
>clients. So of course we are using POI/HSSF and we love it !
>
>But we really need client side validation before the user submits is xls
>template to our website. For that we think about using macros but I've read
>on POI's mailing list archives that POI doesn't support macros yet !
>
>You say it should be easy to implement ?
>
>I would love to contribute and do the modification myself but after
>downloading the source code I realized that it was a little bit more
>complicated than I tought.
>
>Would you have some directions to give me on how to do this tweak ?
>
>Thanks
>
>Regards
>
>Christian Bourque
>
>
>
>  
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to