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

NAME

Spreadsheet::XLSX::Reader::LibXML::XMLReader::Styles - A LibXML::Reader styles base class

SYNOPSIS

        #!/usr/bin/env perl
        
        use Data::Dumper;
        use MooseX::ShortCut::BuildInstance qw( build_instance );
        use Spreadsheet::XLSX::Reader::LibXML::Error;
        use Spreadsheet::XLSX::Reader::LibXML::XMLReader::Styles;
        use Spreadsheet::XLSX::Reader::LibXML::FmtDefault;

        my $file_instance = build_instance(
                  package      => 'StylesInstance',
                  superclasses => ['Spreadsheet::XLSX::Reader::LibXML::XMLReader::Styles'],
                  file         => '../../../../../test_files/xl/styles.xml',
                  error_inst   => Spreadsheet::XLSX::Reader::LibXML::Error->new,
                  format_inst  => Spreadsheet::XLSX::Reader::LibXML::FmtDefault->new(
                                                        epoch_year      => 1904,
                                                        error_inst      => Spreadsheet::XLSX::Reader::LibXML::Error->new,
                                                ),
                );
        print Dumper( $file_instance->get_format_position( 2 ) );

        #######################################
        # SYNOPSIS Screen Output
        # 01: $VAR1 = {
        # 02: 'cell_style' => {
        # 03:     'builtinId' => '0',
        # 04:     'xfId' => '0',
        # 05:     'name' => 'Normal'
        # 06: },
        # 07: 'cell_font' => {
        # 08:     'name' => 'Calibri',
        # 09:     'family' => '2',
        # 10:     'scheme' => 'minor',
        # 11:     'sz' => '11',
        # 12:     'color' => {
        # 13:         'theme' => '1'
        # 14:     }
        # 15:  },
        # 16: 'cell_fill' => {
        # 17:     'patternFill' => {
        # 18:         'patternType' => 'none'
        # 19:      }
        # 20: },
        # 21: 'borderId' => 0,
        # 22: 'cell_coercion' => bless( {
        ~~ Skipped 184 lines ~~
        #206:                             'display_name' => 'Excel_date_164'
        #207:                           }, 'Type::Tiny' ),
        #208: 'numFmtId' => '164',
        #209: 'applyNumberFormat' => '1',
        #210: 'fillId' => 0,
        #211: 'cell_border' => {
        #212:     'top' => undef,
        #213:     'bottom' => undef,
        #214:     'right' => undef,
        #215:     'diagonal' => {
        #216:         'cellStyleXfs' => undef
        #217:      },
        #218:      'left' => undef
        #219: },
        #220: 'xfId' => 0,
        #221: 'fontId' => 0
        #222: };
        #######################################

DESCRIPTION

This documentation is written to explain ways to use this module. To use the general package for excel parsing out of the box please review the documentation for Workbooks , Worksheets , and Cells.

This class is written to get useful data from the sub file 'styles.xml' that is a member of a zipped (.xlsx) archive or a stand alone XML text file of the same format. The styles.xml file contains the format and display options used by Excel for showing the stored data. To unzip an Excel file manually change the \.xlsx extention to \.zip and windows should do (most) of the rest. For linux use an unzip utility. ( Archive::Zip for instance :)

This documentation is the explanation of this specific module. For a general explanation of the class and how to to add or adjust its place in the larger package see the Styles POD.

This module is the simplified way to extract information from the styles file needed when doing high level reading of an Excel spread sheet. In order to do so it subclasses the module Spreadsheet::XLSX::Reader::LibXML::XMLReader and leverages one hard coded role Spreadsheet::XLSX::Reader::LibXML::XMLReader::XMLToPerlData Additionally the module will error if not built with roles that supply two additional methods. The methods are get_defined_excel_format and parse_excel_format_string . The links lead to the default source of these methods in the package. These methods are intentionally not hard coded to this class so that the user can change them at run time. See the attributes "default_format_list" in Spreadsheet::XLSX::Reader::LibXML and "format_string_parser" in Spreadsheet::XLSX::Reader::LibXML for more explanation. Read about the function of each when replacing them. If you want to use the roles as-is, one way to integrate them is with MooseX::ShortCut::BuildInstance. The 'on-the-fly' roles also add other methods (not documented here) to this class. Look at the documentation for those modules to see what else comes with them.

Warnings

This package received a substantial re-write with version v0.38.16. Now this class will now cache the styles values by default. If this causes you heartache please contact me and I will try and mitigate the impact. The goal was to measurably speed up the package.

Method(s)

These are the methods just provided by this class. Look at the documentation for the the two modules consumed by this class for their elements. Spreadsheet::XLSX::Reader::LibXML::XMLReader and Spreadsheet::XLSX::Reader::LibXML::XMLReader::XMLToPerlData

get_format_position( $position, [$header], [$exclude_header] )

    Definition: This will return the styles information from the identified $position (Counting from zero). the target position is usually drawn from the cell data stored in the worksheet. The information is returned as a perl hash ref. Since the styles data is in two tiers it finds all the subtier information for each indicated piece and appends them to the hash ref as values for each type key. If you only want a specific branch then you can add the branch $header key and the returned value will only contain that leg.

    Accepts: $position = an integer for the styles $position. (required at position 0)

    Accepts: $header = the target header key (optional at postion 1) (use the "Attributes" in Spreadsheet::XLSX::Reader::LibXML::Cell that are cell formats as the definition of range for this

    Accepts: $exclude_header = the target header key (optional at position 2) (use the "Attributes" in Spreadsheet::XLSX::Reader::LibXML::Cell that are cell formats as the definition of range for this)

    Returns: a hash ref of data

get_default_format_position( [$header], [$exclude_header] )

    Definition: For any cell that does not have a unquely identified format excel generally stores a default format for the remainder of the sheet. This will return the two tiered default styles information. If you only want the default from a specific header then add the $header string to the method call. The information is returned as a perl hash ref.

    Accepts: $header = the target header key (optional at postion 0) (use the "Attributes" in Spreadsheet::XLSX::Reader::LibXML::Cell that are cell formats as the definition of range for this

    Accepts: $exclude_header = the target header key (optional at position 1) (use the "Attributes" in Spreadsheet::XLSX::Reader::LibXML::Cell that are cell formats as the definition of range for this)

    Returns: a hash ref of data

SUPPORT

TODO

    1. Extend the values saved here out to the sheet and cell level better.

AUTHOR

Jed Lund
jandrew@cpan.org

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

This software is copyrighted (c) 2014, 2015 by Jed Lund

DEPENDENCIES

SEE ALSO

    Log::Shiras

      All lines in this package that use Log::Shiras are commented out