Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: "use Win32::OLE::Const" not having an effect

by HelenCr (Monk)
on Aug 06, 2012 at 12:21 UTC ( #985688=note: print w/replies, xml ) Need Help??

in reply to Re: "use Win32::OLE::Const" not having an effect
in thread "use Win32::OLE::Const" not having an effect

Khen1950fx: thanks for you reply. But it seems that your solution is a workaround the problem. If, on the original system, everything is working fine, why should I say?: no strict qw/subs/;

In my opinion, we should try to find out why  use Win32::OLE::Const 'Microsoft Excel'; is not taking an effect on the XP system. For example, maybe XlExcel8 is defined for Excel 2010 (which is installed on the original system), and has a different name in Excel 2003 (installed on the Windows XP system)? (Just an example)?

Replies are listed 'Best First'.
Re^3: "use Win32::OLE::Const" not having an effect
by dasgar (Curate) on Aug 06, 2012 at 17:41 UTC
    For example, maybe XlExcel8 is defined for Excel 2010 (which is installed on the original system), and has a different name in Excel 2003 (installed on the Windows XP system)?

    Somehow I totally overlooked that the error message in your original post was complaining about "xlExcel8". Combined with the fact that you're using Excel 2010 and Excel 2003, I think I know what's going on. The problem is not with the use Win32::OLE::Const 'Microsoft Excel'; line at all.

    Starting with Excel 2007, Microsoft introduced a new Excel file format and used .xlsx file extension as the default file extension for the new file format. Also, with Excel 2007 and Excel 2010, the default file type when saving a file is the new file type. The user can still choose the older file type if he/she wants to.

    Since you're not providing much code, I have to make some guesses. I'm assuming that you've developed your code on your system with Excel 2010 and wanted to save in the older Excel file format. In that case, you have to specify the file format when saving the file. That's where you're using the xlExcel8 constant. However, that's not a defined constant in the Excel 2003 OLE library. Although there is a free update to Excel 2003 that allows it to use the new file format, I can't say for sure if that will add the xlExcel8 constant to the Excel 2003 OLE library.

    If you're planning to have a script that works with Excel versions 2003, 2007 and 2010, then you'll probably need to check to see what version of Excel is installed in order to know which save methods to call. The way that I've done that before was to look at the code from the OLE browser from the Win32::OLE module to see how it dynamically pulled out information about the available OLE libraries. Then I wrote a subroutine that looked for the "Microsoft Excel X.0 Object Library" and used the X value to determine the Excel version. Excel 2010 is 14, Excel 2007 is 12, and I believe that Excel 2003 is 8.

    Here's how to do a quick test of my assumptions. If my assumptions are correct, you probably have something like the following in your code:

    $book->SaveAs({Filename => $filename, FileFormat => xlExcel8});

    On your Excel 2003 system, try changing that line to the following:

    $book->SaveAs({Filename => $filename});

    If I'm right, that should work on your system running Excel 2003.

      dasgar: excellent! I think you'e hit it right on. You have also guessed right what I was doing: developing on Excel 2010 but saving as Excel 2003 "xls" format, for compatibility.

      I changed that line as you suggested, and the program is running with no errors.

      I haven't tested the save yet, but I suspect it'll be ok. I'll test it and report.

      Thanks a lot for the excellent analysis!


Re^3: "use Win32::OLE::Const" not having an effect
by Corion (Pope) on Aug 06, 2012 at 12:23 UTC

    Win32::OLE::Const outputs warnings for the following code:

    >perl -wlE "use Win32::OLE::Const 'Some Madeup Library'; print 'All is + well'" No type library matching "Some Madeup Library" found at -e line 1 Win32::OLE(0.1709): GetOleTypeLibObject() Not a Win32::OLE::TypeLib ob +ject at ...

    ... so you will have to look through the Microsoft documentation on Excel to find out what type library to use when.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985688]
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
[choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
[Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
choroba scratches a "how"
[Corion]: choroba: Exactly... But maybe that's just because I'm old and grumpy ;)
[Corion]: But maybe that could also be a nice talk, how to restructure your DBIx::Class-based app to remove 1+n-style query patterns
[Corion]: In theory, that should be easy because you should have the "where" clause from part 1 of the patterns and then do the corresponding single select using that where clause to select all rows in one go for the n other parts.
[Corion]: But in practice I don't see any obvious places documented in DBIx::Class where one would do that and then just feed hash lookups instead of DB lookups for ->has_many results

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-09-25 11:11 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (279 votes). Check out past polls.