Parsing Excel spreadsheet on osx?
|
|
Thread rating:  |
Adam Witney - 16 Jan 2005 18:10 GMT Hi,
I am trying to parse an Excel spreadsheet, but a simple script from the pod
use strict; use Spreadsheet::ParseExcel;
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse('test.xls');
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]; print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC); } } }
This gives no output at all. Any ideas if this should work on OSX?
Thanks
Adam
 Signature This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
John Delacour - 16 Jan 2005 22:28 GMT >I am trying to parse an Excel spreadsheet, but a simple script from the pod > >This gives no output at all. Any ideas if this should work on OSX? Could this have any relevance? :
______________ Latest Release: Spreadsheet-ParseExcel-0.2603
DESCRIPTION Spreadsheet::ParseExcel makes you to get information from Excel95, Excel97, Excel2000 file. ______________
Paul McCann - 16 Jan 2005 22:36 GMT Hi Adam, you asked...
[[script deleted]]
> This gives no output at all. Any ideas if this should work on OSX? Yes, it works perfectly on my machine. I made a new spreadsheet "test.xls", inserted some simple data on two separate sheets, and then ran the script you provided. Output was
--------- SHEET:Sheet1 ( 0 , 0 ) =>One ( 1 , 0 ) =>two ( 2 , 0 ) =>three --------- SHEET:Sheet2 ( 0 , 0 ) =>Four ( 1 , 0 ) =>five ( 2 , 0 ) =>six --------- SHEET:Sheet3
As far back as I can remember Spreadsheet::ParseExcel (and WriteExcel) have worked fine on Mac OS X. Maybe try reinstalling the former (and watch the test output for any signs?).
Cheers, Paul
John Horner - 17 Jan 2005 03:51 GMT I have a very useful Perl::Tidy Filter in BBEdit, though I'm not quite sure where I got it from.
Essentially it takes input from the selection of the current window, and when invoked, writes Tidy'd code back to the selection.
It's terribly simple, in fact I'll post the entire thing here (minus a couple of comments):
#!/usr/bin/perl -wn use Perl::Tidy; BEGIN { my $input_string = ""; my $output_string = ""; } $input_string .= $_; END { Perl::Tidy::perltidy( source => \$input_string, destination => \$output_string, );
print "$output_string\n"; } __END__
my question is, how can I create the same sort of script which will use HTML::Tidy?
Both the module and the library are installed and running OK on my Mac, but I can't seem to get it to work, in fact I can't even figure out from the documentation how to get any output from it at all!
According to http://search.cpan.org/~petdance/HTML-Tidy-1.04/lib/HTML/Tidy.pm the module only has six methods, none of which returns my HTML to me in any form -- am I missing something? The messages say things like "deleting empty <p> tag", but if it doesn't return anything, so what? Should I be using the API for libtidy itself, and if so, how?
------------------------------------------------------------ "Have You Validated Your Code?" John Horner (+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ------------------------------------------------------------
Paul McCann - 18 Jan 2005 00:07 GMT Hi John, you wrote...
> my question is, how can I create the same sort of script which will > use HTML::Tidy? > > Both the module and the library are installed and running OK on my > Mac, but I can't seem to get it to work, in fact I can't even figure > out from the documentation how to get any output from it at all! I think HTML::Tidy doesn't offer what you're seeking: looks like it's a validation tool, not a "pretty-print" tool. So your output is empty if things are well in the world of your html, and warnings/errors if there are problems validating the string HTML::Tidy is fed.
The following works as a filter in BBEdit, but (as above) I don't think it'll do what you're seeking!
Do the items in the "Markup->Tidy" submenu do what you're seeking? I'm pretty sure they hook into a copy of HTML Tidy that's embedded in BBEdit.
Cheers, Paul ------------------------------------------------------------------------------ #!/usr/local/bin/perl -w use strict; use HTML::Tidy; local $/; my $input=<>; my $dummyfilename='input'; my $tidy = new HTML::Tidy; $tidy->parse($dummyfilename, $input ); for my $message ( $tidy->messages ) { print $message->as_string; } ------------------------------------------------------------------------------
John Horner - 18 Jan 2005 01:30 GMT >I think HTML::Tidy doesn't offer what you're seeking: looks like it's a >validation tool, not a "pretty-print" tool. So your output is empty >if things are well in the world of your html, and warnings/errors if >there are problems validating the string HTML::Tidy is fed. Well, yes and no. Perhaps it seems that way because you're seeing the HTML::Tidy documentation offering only to do those things.
But having installed the tidy library on my Mac, I can type
tidy test.html
at the command line and have it give warnings and also print to STDOUT a fixed version of my file, e.g. it might say 'Missing attribute on line 6', and then it will print out a new version of the file with that attribute added.
The option -i will do indenting, i.e. rudimentary formatting, and the -m option will edit the file in place rather than dump the corrected version out.
So I still remain baffled by the module. Does its "clean" function transform a string in place? It doesn't seem to. Where are the options? Is it perhaps confused about where tidy is on my system (/opt/local/bin/tidy) ? ------------------------------------------------------------ "Have You Validated Your Code?" John Horner (+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ------------------------------------------------------------
_brian_d_foy - 18 Jan 2005 03:23 GMT > Do the items in the "Markup->Tidy" submenu do what you're seeking? I'm > pretty sure they hook into a copy of HTML Tidy that's embedded in BBEdit. There is an HTML Tidy in BBEdit, but it only works on the whole document. The filter posted earlier works with the current selection, which I think was the point of the question. :)
 Signature brian d foy, comdog@panix.com
|
|
|