in reply to Parse error in Spreadsheet::ParseExcel::Simple

igelkott:

I'm not certain I understand the problem. Is it that the sheets aren't in the order you're expecting or that your code can't find the sheets until others are deleted?

If it's the first case, try accessing the sheets by name rather than index. That way you'll be able to find them even if they're reordered or created in a different order than you expect. (Of course, then you're relying on people not renaming the sheets!)

I don't have any ideas for you if it's the second case.

...roboticus
  • Comment on Re: Parse error in Spreadsheet::ParseExcel::Simple

Replies are listed 'Best First'.
Re^2: Parse error in Spreadsheet::ParseExcel::Simple
by igelkott (Priest) on Apr 21, 2008 at 15:39 UTC
    accessing the sheets by name rather than index

    I tried doing through Spreadsheet::ParseExcel rather than the "simple" version.

    I get the sheet names in the right order (not that that is so important) but the contents appear with a different sheet. For example:

    Sheet foo contents of bar Sheet bar contents of baz Sheet baz empty

    What I want is the data from "foo" (what I expect to be the first sheet). As you suggest, if I could get it by name, all would be saved ... even if the event would be hard to explain.

    I was a bit vague regarding the "reappearing data" because it's just too weird. In excel, I deleted the other sheets from the file and found that I could then find my "foo" data on the "foo" sheet (the only one left).

      igelkott:

      I suspect that it's not a corrupt file, but that the sheets may not be stored in order of appearance on the tab bar. To check it, try adding the method:

      sub sheet_name { shift->{sheet}->{Name}; }

      to the Spreadsheet::ParseExcel::Simple.pm file, then you can print the sheet name associated with the sheet to check it out. Then, of course, let me know what you discover!

      ...roboticus
        roboticus,

        Added your method to Simple.pm and a print $sheet->sheet_name to the script shown in the original post.

        The sheet names appear in the correct order but the contents do not. Specifically, I get:

        name = sheet 1
        contents = sheet 4
        name = sheet 2
        contents = sheet 2
        name = sheet 3
        contents = sheet 3
        name = sheet 4
        contents = empty

        It's the contents of sheet 1 I'm interested in but can't find. This is like the test with Spreadsheet::ParseExcel above but I was a bit vague (inaccurate) there.

        How to solve my immediate issue is one thing but it's of course more interesting to figure out if this has identified a general bug. I'll play with Data::Dumper, etc to see if anything interesting comes up but not sure how far I'll get into the module source code...