poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trey Hyde <th...@centraldesktop.com>
Subject Re: Issues losing a drawing part when saving an ooxml filesystem
Date Wed, 13 Oct 2010 17:40:32 GMT

On Oct 13, 2010, at 2:37 AM, Nick Burch wrote:

> On Tue, 12 Oct 2010, Trey Hyde wrote:
>> I've been injecting custom document properties with POI in both OOXML and OLE files
for about 4 months now covering a very large number of documents.  I do have one customer
complaining when they open my meta-data injected version of their file that Excel complains
about a missing drawing part.
> 
> Do all files with drawings get affected, or only some? For a file that will display the
problem, if you open and save (without making any changes) do you see the problem? Or is it
only after you make other changes that the drawing gets lost?


The drawings all seem intact but only tangible difference I see is the missing hyperlink rel
in drawing1.    I  just modified the code to not actually make any changes and I see the same
thing.   See the code below.   The commented region is what the core of my utility does ...
  Open the pakage, open the props, add / modify custom properties, commit the properties,
save a copy of the package.    Just doing that (even when not executing the property part)
is dropping that rId1 hyperlink relation which is causing Excel 2007 to freak out.   Mac Office
doesn't complain.   I'm not even sure what the image it is complaining about is or how it
was added.

    public boolean save(Map<String, String> props) {
        try {

            OPCPackage docPackage = OPCPackage.openOrCreate(input);
            //, PackageAccess.READ_WRITE
            
            POIXMLProperties xmlprops = new POIXMLProperties(docPackage);

//            CustomProperties custom = xmlprops.getCustomProperties();
//            CTProperties ct = custom.getUnderlyingProperties();
//            CTProperty[] ctp = ct.getPropertyArray();
//
//            for (String key : props.keySet()) {
//                if (custom.contains(key)) {
//                    for (CTProperty prop : ctp) {
//                        //System.out.println(prop.getName() + " " + prop.getLpwstr());
//                        if (prop.getName().equals(key)) {
//                            prop.setLpwstr(props.get(key));
//                        }
//                    }
//                } else {
//                    custom.addProperty(key, props.get(key));
//                }
//
//            }

            xmlprops.commit();
            File output = File.createTempFile("office-ooxml-",null);
            System.out.println(output.getCanonicalPath());
            docPackage.save(output);
            //docPackage.flush();

            return true;
        } catch (Exception ex) {
            Logger.getLogger(OpenXMLMDWriter.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message