Perhaps you can adapt this
#!perl use strict; use Archive::Zip::MemberRead; use XML::Twig; use Text::CSV; Archive::Zip::MemberRead->setLineEnd(); my $csv = Text::CSV->new ( {binary=>1, eol=>"\012"} ) or die "Cannot use CSV: ".Text::CSV->error_diag(); my $infile = 'header1.xlsx'; my $outfile = 'results.csv'; open my $fh_out,'>',$outfile or die "Could not open $outfile: $!"; my @sheet; my $zip = Archive::Zip->new($infile); for my $name ($zip->memberNames()){ if ($name =~ /sheet(\d+).xml$/){ $sheet[$1] = $name; } } my @fields = ('oddHeader','evenHeader','oddFooter','evenFooter'); $csv->print($fh_out, [$infile,scalar localtime()]); $csv->print($fh_out, ['Sheet',@fields]); my %text=(); for my $no (1..$#sheet) { %text=(); process_sheet( $sheet[$no] ); my @row = map{ $text{$_} } @fields; $csv->print($fh_out, [$no,@row]); } $fh_out->close or die "$!"; print "Results written to $outfile\n"; sub process_sheet { my $filename = shift; print "Extracting text from : $filename\n"; my $fh_in = Archive::Zip::MemberRead->new($zip, $filename); my $xml = $fh_in->getline(); $fh_in->close(); my $twig = XML::Twig->new( keep_spaces=>1, twig_roots => { 'headerFooter' => \&get_text }, ); $twig->parse( $xml ); } sub get_text { my ($t,$elt) = @_; for ($elt->children){ my $text = $_->text; # remove left center right format codes $text =~ s/&[LCR]/ /g; $text{$_->name} = $text ; } }
poj

In reply to Re^2: Print Only header Excel by poj
in thread Print Only header Excel by TheStig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.