Am Dienstag, den 09.08.2005, 18:16 +0000 schrieb Andrew Leonard:
> Hello, I am trying to edit the properties of various word, powerpoint, and 
> excel
> files and I am having some trouble.  The example on the website
> (http://jakarta.apache.org/poi/hpsf/how-to.html#sec4) shows how to create a 
> new
> document and its properties, so when I use that code, it overwrites my current
> files.  I have gotten it so that I can read in the properties by feeding the
> MutablePropertySet the PropertySet of the file, like this:
> MutablePropertySet mps = new MutablePropertySet(new PropertySet(si));
> While debugging and looking at it, it has all the properties from the file I
> read in plus the properties I added/changed, which is good.  The big problem I
> am having is writing these changes back to the file.  I can write the new
> document properties back fine, but that is all it writes back (the original 
> file
> is lost).  How can I get around this?  Any help will be appreciated.

Yep, that's correct. The example in the creates a *new* POI filesystem
and writes just the property set into it - and nothing else. If there
was already a file with the same name as the new POI filesystem it will
be *overwritten*.

Your issue is not HPSF related but POIFS related. If you want to keep
what is already there in your file, you must open the POI filesystem
(aka your Word, Excel or whatever file) using the classes in the
org.apache.poi.poifs.filesystem packages (see the API documentation in
<http://jakarta.apache.org/poi/apidocs/index.html>). It allows you to
open a POI filesystem by reading it into memory, read and write specific
documents like property sets, and write the modified POI filesystem to a
disk file.

There is an example program in
src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
which does something similar: It read a POIFS using the event filesystem
(package org.apache.poi.poifs.eventfilesystem) and copies all streams to
a new POIFS using the org.apache.poi.poifs.filesystem classes.

Best regards
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  [EMAIL PROTECTED]
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

Public key fingerprint: E4E4386515EE0BED5C162FBB5343461584B5A42E

European Parliament rejects software patent bill: 
http://news.bbc.co.uk/1/hi/technology/4655955.stm

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to