Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Reading Excel with different format

by 9mohit2 (Sexton)
on Aug 29, 2016 at 12:16 UTC ( [id://1170701]=perlquestion: print w/replies, xml ) Need Help??

9mohit2 has asked for the wisdom of the Perl Monks concerning the following question:

I have written code to access a Excel using the Win32::OLE module but I am facing problem with an excel which gives the alert 'file format and extension do not match'. I have managed to stop the popup by some changes in regedit (http://stackoverflow.com/questions/28403642/how-to-fix-file-format-and-extension-dont-match) but still the code gives error on reading.


Note - The excel has normal data in 3 columns

Replies are listed 'Best First'.
Re: Reading Excel with different format
by GotToBTru (Prior) on Aug 29, 2016 at 12:22 UTC

    Kind of an obvious question, but do the file format and extension match?

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      To expand GotToBTru's response: The SO post you linked hints that the StackOverflow-OriginalPoster had somehow create a modern (.xlsx) spreadsheet with the old (.xls) extension. Thus, I'm guessing the same has happened to you (or the reverse: an old spreadsheet created with the new naming convention).

      So, here are some possible routes to go down:

      1. If you want to just fix it for this specific file, just change the file's extension to match the real type (if it's a modern spreadsheet with a .xls extension, rename it .xlsx, or .xlsm if it has macros; if it's an older spreadsheet with a modern extension, rename it .xls).
      2. If many files are going to be created in the same manner, you'll want to fix the process that created the spreadsheet, rather than just manually (or automatically) renaming mis-created files for years to come. If you would like help with this, and if the code that creates the spreadsheet(s) is also in Perl (using Win32::OLE or any of the excel-spreadsheet-manipulating modules), feel free to post a small, self-contained example (SSCCE) that shows how the spreadsheet is created and saved (and, if possible, also shows the error above when the file is closed and then re-opened). Given that, we might be able to help you fix the code. If the process that creates the spreadsheet isn't in Perl, you should probably either talk to the creator/maintainer of that process (if possible), or find a forum that deals with that environment (Visual Basic for Applications, c/c++, etc).
      3. If the procedure that creates the excel spreadsheet(s) is non-Perl and/or outside your control or ability to influence, you might want to go the route of automating the rename process. In that case, Perl has a nice builtin rename function. If you write up your rename script, but it's not working quite right, feel free to ask us questions.

      Hope this helps

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1170701]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found