parsing .xls-files with indentations

Tag: excel , perl , parsing , indentation , xls Author: w1y2h3wuyanhui Date: 2013-09-17

I have excel file with 5 levels of indentations so I guess I need Spreadsheet::ParseExcel::Format but when I'm trying $format->{Indent} (just like in synopsis) perl says:

Global symbol "$format" requires explicit package name

I was trying different ways, also Spreadsheet::ParseExcel::Format->new() and others, but still no success.

What is right synopsis or is there other ways to parse indentations from xls-files? Maybe some binary? (xlhtml and xls2csv don't care about indents at all :( )

please show some runnable code

Other Answer1

The site linked to by @mpapec seems to claim to have a solution from John McNamara:

#!/usr/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;

my $parser   = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');

if ( !defined $workbook ) {
    die $parser->error(), ".\n";

for my $worksheet ( $workbook->worksheets() ) {

    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();

    for my $row ( $row_min .. $row_max ) {
        for my $col ( $col_min .. $col_max ) {

            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

            my $format = $cell->get_format();

            print "Row, Col    = ($row, $col)\n";
            print "Value       = ", $cell->value(), "\n";
            print "Indent      = ", $format->{Indent}, "\n";

            print "\n";