NAME
Spreadsheet::XLSX::Reader::LibXML::FormatInterface - Interface for XLSX format parser
SYNOPSYS
#!/usr/bin/env perl
use MooseX::ShortCut::BuildInstance 'build_instance';
use Spreadsheet::XLSX::Reader::LibXML::FmtDefault;
use Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings;
use Spreadsheet::XLSX::Reader::LibXML::FormatInterface;
use Spreadsheet::XLSX::Reader::LibXML;
my $formatter = build_instance(
package => 'FormatInstance',
# The base United State localization settings - Inject your customized format class here
superclasses => [ 'Spreadsheet::XLSX::Reader::LibXML::FmtDefault' ],
# ParseExcelFormatStrings => The Excel string parser generation engine
# FormatInterface => The top level interface defining minimum compatability requirements
add_roles_in_sequence =>[qw(
Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
Spreadsheet::XLSX::Reader::LibXML::FormatInterface
)],
target_encoding => 'latin1',# Adjust the string output encoding here
datetime_dates => 1,
);
# Set specific default custom formats here
$formatter->set_defined_excel_formats( 0x2C => 'MyCoolFormatHere' );
# Use the formatter like Spreadsheet::ParseExcel
my $parser = Spreadsheet::XLSX::Reader::LibXML->new;
my $workbook = $parser->parse( '../t/test_files/TestBook.xlsx', $formatter )
# This is an alternate way
$workbook = Spreadsheet::XLSX::Reader::LibXML->new(
file_name => '../t/test_files/TestBook.xlsx',
# Adding the formatter is not strictly necessary unless you want to customize it
formatter_inst => $formatter,
);
DESCRIPTION
In general a completly built formatter class as shown in the SYNOPSYS is used by this package to turn unformatted data into formatted data. This is generally used in Excel to implement localization of the output. The general localization options are then stored at the workbook level. This includes any custom output formatting defined by the application user. The selection of which output formatting to apply to which data element is stored in the individual worksheet. This class provides the implementation of the localizations. The sub modules of the class above provide additional options to adjust the format applied for requested default positions and they also provide helper functions to generate user defined and applied formats as well. Review the method descriptions below, the sub module documentation, and the documentation for "set_custom_formats( $key => $format_object_or_string )" in Spreadsheet::XLSX::Reader::LibXML::Worksheet in order to understand the full range of configurability provided when interacting with the overall spreadsheet parser.
Module Description
This module is written to be an Interface for the Formatter class used in Spreadsheet::XLSX::Reader::LibXML 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::XLSX::Reader::LibXML. However porting the underlying elements to 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.
To use the general package for excel parsing out of the box please review the documentation for Workbooks , Worksheets , and Cells
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 workbook parsing will as a minimum require this module (role/interface) which will require these methods.
parse_excel_format_string( $string, $name )
Definition: This is the method to convert Excel format strings to code that will translate raw data from the file to formatted output in the form defined by the string. It is possible to pass a format name that will be incorperated so that the method $coercion->display_name returns $name.
Default source: "parse_excel_format_string( $string, $name )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
get_defined_conversion( $position )
Definition: This method returns the code for string conversion for a pre-defined conversion by position.
Default source: "get_defined_conversion( $position )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
set_target_encoding( $encoding )
Definition: This sets the output $encoding for strings.
Default source: "set_target_encoding( $encoding )" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
get_target_encoding
Definition: This returns the output encoding definition for strings.
Default source: "get_target_encoding" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
has_target_encoding
Definition: It is possible to not set a target encoding in which case any call to decode data acts like a pass through. This returns true if the target encoding is set.
Default source: "has_target_encoding" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
change_output_encoding( $string )
Definition: This is the method call that implements the output encoding change for $string.
Default source: "change_output_encoding( $string )" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
get_excel_region
Definition: It may be useful for this instance to self identify it's target output. This method returns that value
Default source: "get_excel_region" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
set_defined_excel_formats( %args )
Definition: This allows for adjustment and or addition to the output format lookup table. The default implementation allows for multiple ways to do this so please review that documentation for details.
Default source: "set_defined_excel_formats( %args )" in Spreadsheet::XLSX::Reader::LibXML::FmtDefault
set_cache_behavior( $Bool )
Definition: This sets the flag that turns on caching of built format conversion code sets
Default source: "set_cache_behavior( $Bool )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
set_date_behavior( $Bool )
Definition: This sets the flag that inturupts the date formatting to return a datetime object rather than a date string
Default source: "set_date_behavior( $Bool )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
set_european_first( $Bool )
Definition: This also sets a flag dealing with dates. The date behavior that is affected here involves parsing date strings (not excel date numbers) and checks the DD-MM-YY form before it checkes the MM-DD-YY form when attempting to parse date strings.
Default source: "set_european_first( $Bool )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
set_workbook_inst( $instance )
Definition: This sets the workbook instance in the Formatter instance. Spreadsheet::XLSX::Reader::LibXML will overwrite this attribute if the end-user sets it. The purpose of this instance is for the formatter to see some of the workbook level methods;
"error" in Spreadsheet::XLSX::Reader::LibXML
"set_error" in Spreadsheet::XLSX::Reader::LibXML
Default source: "set_workbook_inst( $instance )" in Spreadsheet::XLSX::Reader::LibXML::ParseExcelFormatStrings
SUPPORT
TODO
1. Attempt to merge _split_decimal_integer and _integer_and_decimal
AUTHOR
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
version 0.77
Carp - confess
Type::Tiny - 1.000
DateTimeX::Format::Excel - 0.012
Clone - clone
Spreadsheet::XLSX::Reader::LibXML::Types
requires;
get_excel_region
set_error
get_defined_excel_format
SEE ALSO
Spreadsheet::ParseExcel - Excel 2003 and earlier
Spreadsheet::XLSX - 2007+
Spreadsheet::ParseXLSX - 2007+
All lines in this package that use Log::Shiras are commented out