in reply to Can SpreadSheet::ParseExcel::Font retrieve a cell's formatting?
use Spreadsheet::ParseExcel; use strict; my $fname = shift; my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($fname); my($iR, $iC, $oWkS, $oWkC); foreach my $oWkS (@{$oBook->{Worksheet}}) { print "--------- SHEET:", $oWkS->{Name}, "\n"; for(my $iR = $oWkS->{MinRow}; defined( $oWkS->{MaxRow} ) && $iR <= $oWkS->{MaxRow}; $iR++) { for(my $iC = $oWkS->{MinCol}; defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol}; $iC++) { $oWkC = $oWkS->{Cells}[$iR][$iC]; if ( $oWkC ) { print "( $iR , $iC ) =>", $oWkC->Value, "\n"; my $format = $oWkC->{Format}; my $font = $format->{Font}; if ( $font->{Italic} ) { print( " (italic)\n" ); } } } } }
The clue is to get hold of the 'Font' object from the 'Format' object of the cell in question.
The output I get when feeding in an example spreadsheet I created myself was:
[root@monarch monarch]# perl /tmp/parseexcel.pl /tmp/deleteme.xls --------- SHEET:Sheet1 ( 1 , 1 ) =>This cell is normal ( 2 , 1 ) =>This cell is italic (italic) ( 3 , 1 ) =>This cell is normal --------- SHEET:Sheet2 --------- SHEET:Sheet3
Update: corrected spelling of CPAN module
|
|---|