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

NAME

Spreadsheet::Reader::Format - Formatting for various spreadsheet readers

perl version Build Status Coverage Status github version CPAN version kwalitee

SYNOPSYS

        #!/usr/bin/env perl
        use MooseX::ShortCut::BuildInstance 'build_instance';
        use Spreadsheet::Reader::Format;
        use Spreadsheet::Reader::Format::FmtDefault;
        use Spreadsheet::Reader::Format::ParseExcelFormatStrings;
        use Spreadsheet::Reader::ExcelXML;
        my $formatter = build_instance(
                package => 'FormatInstance',
                # The base United State localization settings - Inject your customized format class here
                superclasses => [ 'Spreadsheet::Reader::Format::FmtDefault' ],
                # ParseExcelFormatStrings => The Excel string parser generation engine
                # Format => The top level interface defining minimum compatability requirements
                add_roles_in_sequence =>[qw(
                        Spreadsheet::Reader::Format::ParseExcelFormatStrings
                        Spreadsheet::Reader::Format
                )],
                target_encoding => 'latin1',# Adjust the string output encoding here
                datetime_dates  => 1,
        );

        # Use in a standalone manner
        my      $date_string = 'yyyy-mm-dd';
        my      $time           = 55.0000102311;
        # Build a coercion with excel format string: $date_string
        my      $coercion       = $formatter->parse_excel_format_string( $date_string );
        # Checking that a DateTime object was returned
        print ref( $coercion->assert_coerce( $time ) ) . "\n";
        # Checking that the date and time are presented correctly: 1904-02-25T00:00:01
        print $coercion->assert_coerce( $time ) . "\n";

        # Set specific default custom formats here (for use in an excel parser)
        $formatter->set_defined_excel_formats( 0x2C => 'MyCoolFormatHere' );

        # Use the formatter like Spreadsheet::ParseExcel
        my $parser      = Spreadsheet::Reader::ExcelXML->new;
        my $workbook = $parser->parse( '../t/test_files/TestBook.xlsx', $formatter );

DESCRIPTION

In general a completly built formatter class as shown in the SYNOPSYS is already used by the package Spreadsheet::Reader::ExcelXML to turn unformatted data into formatted data. The purpose is to allow the Excel equivalent of localization of the output. The general localization options are mostly found at the workbook level. Individual cells also contain information about how that cell data should be formatted.

It is possible to insert alternate roles in the Formatter build or use methods to customize the defaults used by the formatter for use in the Spreadsheet reader. It is also possible to use the formatter to output custom format code for post processing output..

Module Description

This module is written to be an Interface for the Formatter class used in Spreadsheet::Reader::ExcelXML so that the core parsing engine and the regional formatting settings for the parser can easily be swapped. This interface really only defines method requirements for the undlerlying instance since the engine it uses was custom-built for Spreadsheet::Reader::ExcelXML. However, adding a shim to this package so it can be used by Spreadsheet::ParseExcel (for example) should be easier because of the abstraction.

This module does not provide unique methods. It just requires methods and provides a uniform interface for the workbook package. Additional attributes and methods provided by the sub modules may be available to the instance but are not in the strictest sence required.

Methods

These are the methods required by this interface. Links to the default implementation of each method are provided but any customization of the formatter instance for Spreadsheet parsing will as a minimum require these methods.

parse_excel_format_string( $string, $name )

get_defined_conversion( $position )

set_target_encoding( $encoding )

get_target_encoding

has_target_encoding

change_output_encoding( $string )

get_excel_region

set_defined_excel_formats( %args )

set_cache_behavior( $bool )

set_date_behavior( $bool )

set_european_first( $bool )

set_workbook_inst( $instance )

SUPPORT

TODO

    1. Nothing yet

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) 2016, 2017 by Jed Lund

DEPENDENCIES

SEE ALSO

perl monks