The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenXML::Properties - Read/Write custom properties from Microsoft documents in OpenXML format (MS Office 2007 onwards).

VERSION

Version 0.01

SYNOPSIS

    use OpenXML::Properties;

    $doc = OpenXML::Properties->new(FileName => 'C:\temp\test.xlsx');

    # To check if a custom property exists in the document
    if ($doc->has_custom_property($custom_property_name))
    {
        print "Document has $custom_property_name\n";
    }

    # To get the number of custom properties in the document
    $count = $doc->has_custom_properties
        print "Document has $count properties\n";
    

    # To list all custom properties in the document
    my @props = $doc->custom_properties_names;
    print "The document has the following custom properties: \n", join("\n", @props);

        # To list all custom property names along with values
        my %props = $doc->custom_properties;

        # To add a custom property
    my $err = $doc->add_custom_property($custom_property_name, $custom_property_value);
    print "Adding failed with error: $err\n" if $err;


    # To remove an existing custom property
    $err = $doc->remove_custom_property($custom_property_name);
    print "Removing failed with error: $err\n" if $err;

    $doc->save();

DESCRIPTION

OpenXML::Properties helps to check, set and remove custom properties in a MS Office Word, Excel and Powerpoint documents in OpenXML format, i.e., 2007 and higher.

Custom properties in documents of older versions of MS Office could be accessed/modified using the module Win32::OLE, but there are no such modules for OpenXML documents.

OpenXML documents are nothing but a group of xml files combined in a zip format.

Please check http://msdn.microsoft.com/en-us/office/bb265236.aspx for further info on OpenXML

This module uses Archive::Zip to read the Office files (.docx, .xlsx and .pptx) and XML::Xpath to read/write the xml files.

Code is written using Moose.

NOTE

This module changes only the custom properties in the document but does not change the data. However, since this is still in a development phase, please take a backup of your documents before using this module.

Constructor

    The constructor to OpenXML::Properties requires the FileName argument. The FileName is the file to which you wish to view/add/remove custom properties.

        my $doc = OpenXML::Properties->new(FileName => 'C:\temp\test.xlsx');

    The constructor also takes an optional 'verbose' parameter.

        my $doc = OpenXML::Properties->new(FileName => 'C:\temp\test.xlsx', verbose => 1);

    'verbose' will write debugging information to 'C:\temp\openxml_properties_log_$$.txt' where $$ is the pid of the process.

Methods

add_custom_property($custom_property_name, $custom_property_value)

add_custom_property requires 2 parameters to be passed, the property name and value to be applied to the document. It returns error as a string, if any. If nothing is returned, then the property was added successfully.

    $doc->add_custom_property($custom_property_name, $custom_property_value);
remove_custom_property($custom_property_name)

remove_custom_property requires 1 parameter, i.e., the property name to be removed from the document. It returns error as a string, if any. If nothing is returned, then the property was removed successfully.

    $doc->remove_custom_property($custom_property_name);
has_custom_property($custom_property_name)

has_custom_property checks if the custom property exists. Returns true if exists, false if it does not.

        if ($doc->has_custom_property($custom_property_name))
    {
        print "Document has $custom_property_name\n";
    }
has_custom_properties($custom_property_name)

has_custom_properties returns the number of custom properties currently applies to the document.

    $count = $doc->has_custom_properties
custom_properties

custom_properties returns all custom property names and values in the document, as a hash.

    my %props = $doc->custom_properties;
custom_properties_names

custom_properties_names returns all custom properties in the document, as an array.

    my @props = $doc->custom_properties_names;

AUTHOR

Ananth Venugopal, <ananthbv at gmail.com>

BUGS

Please report any bugs or feature requests to bug-openxml-properties at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OpenXML-Properties. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc OpenXML::Properties

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2012 Ananth Venugopal.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.