Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

OLE Excel.Application Vs Spreadsheet::WriteExcel

by nocool (Novice)
on Aug 17, 2010 at 21:09 UTC ( [id://855616]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,
I am very new to Perl language and want to generate Excel file with formula using Perl.
I found two possible ways to initialize the Excel sheet object in Perl:
1. OLE Excel.Application
2. Spreadsheet::WriteExcel

I don’t know the difference between these two and want to know which one is suitable for my requirement.
also what is the limitations of these two ?
  • Comment on OLE Excel.Application Vs Spreadsheet::WriteExcel

Replies are listed 'Best First'.
Re: OLE Excel.Application Vs Spreadsheet::WriteExcel
by dasgar (Priest) on Aug 17, 2010 at 22:32 UTC

    I do know that there are some limitations with Spreadsheet::WriteExcel and the author of that module acknowledged two such limitations just yesterday (Spreadsheet::WriteExcel and type=line/area), but I don't know what all of the limitations are since I don't use that module.

    Personally, I primarily use Perl in Windows. As such, I use Win32::OLE to control Excel directly from Perl. As Corion pointed, that does require Excel to be installed. Basically, anything that you can do manually with a mouse and keyboard in Excel, you can do with Win32::OLE and Excel.

    As for your scenario (running on a Unix based system), it sounds like Spreadsheet::WriteExcel may be the better route to go since Excel is a Windows only application.

Re: OLE Excel.Application Vs Spreadsheet::WriteExcel
by Corion (Patriarch) on Aug 17, 2010 at 21:12 UTC

    Using OLE requires Microsoft Excel installed. Spreadsheet::WriteExcel does not require Excel installed.

    Using Excel might be faster in some situations. You don't tell us about your requirements, so it's hard to judge.

      Thanks for the reply Corion.

      My requirement is to generate the excel files with calculated data and graph on Unix based system. Also I have to call Crystal Reports from the same Perl code.
      Can we use OLE Microsoft Excel in this scenario ?
      Please sugest...

        Please read my above reply and consult with your unix system adminitrator whether you can install Microsoft Excel and Crystal Reports there.

Re: OLE Excel.Application Vs Spreadsheet::WriteExcel
by vek (Prior) on Aug 17, 2010 at 21:12 UTC
    I've successfully used Spreadsheet::WriteExcel in production for years. I swear by it in fact. It's a simple install from CPAN so give it a whirl.
      Vek, Thanks for the reply.

      My requirement is to generate the excel files with calculated data and graph on Unix based system. Also I have to call Crystal Reports from the same Perl code.
      Can we use OLE Microsoft Excel in this scenario ?
      Please sugest...
        I don't have any experience of OLE Microsoft Excel to be honest. I'm confused though, isn't Crystal Reports a Windows based reporting tool? Are you going to run your excel generator on a Windows box or a Unix box?
Re: OLE Excel.Application Vs Spreadsheet::WriteExcel
by camenix (Acolyte) on Aug 17, 2010 at 22:44 UTC
    use Win32::OLE,it is my selection.You can control everything in Excel.The only problem I met is this:In Excel2000,when you exit Excel created by your script,the previous Excel application may exit too.
Re: OLE Excel.Application Vs Spreadsheet::WriteExcel
by furry_marmot (Pilgrim) on Aug 19, 2010 at 01:01 UTC

    OLE is a specific Microsoft technology. It is based on and extends the older DDE protocols. It works on Windows only. Unless it works in WINE and is callable from a Unix/Linux process, you will not be able to use it.

    I have used Spreadsheet::WriteExcel a lot, but not to create graphs. Just read the docs for starters.

    If that is not sufficient for your needs, consider writing two spreadsheets. One is a pre-created template that you copy and rename as necessary. The other is a data file. When you load the template, it will have a VBA script to load the pre-formatted-by-your-Perl-script data, which will automatically update the associated graph.

    I hope this helps

    --marmot

    Update: I've decided my reply might not have been as clear as I meant it, and I see no one else has quite hit this point, so here it is: OLE is a Windows API. It doesn't work on non-Windows systems. So that should help clarify what you can use right there.

    OLE, with respect to Excel, is used as a form of automation. When creating a spreadsheet via Excel, it looks like magic hands open Excel, enter data, create graphs, etc. It's pretty easy, and VERY impressive to newbs and managers. :-) You can actually hide the updates while it's running, and that runs faster, but it's not as cool-looking.

    For what it's worth, it's pretty cool. Excel becomes an OLE server -- you send it commands and it does what you tell it. Technically, you create a Workbook object, then a Worksheet object inside that, then address cells, entering data or formatting them, creating charts, etc. You have absolute control over Excel. The easiest way to get started is to record a macro in Excel, doing whatever you need to do, and then save it as a Visual Basic for Applications script. It's very straightforward to convert it to Perl. You can enter data into cells, say A10-C10 through A20-C20, then find the relevant lines in the VBA script. Copy one of those into your script and convert it to A$row-C$row and write a loop to fit your current data.

    You end up writing a Perl wrapper around a VBA script, which is only a drawback if you want to do something more Perlish. If you're working on Windows and you're using Perl to generate your data, it's a fine way to go, especially if you're getting your feet wet with Perl but are more familiar with VBA. The other potential drawback is, again, that it's Windows only.

    Spreadsheet::WriteExcel creates a binary file and doesn't care what platform it's on. It's mature, well-tested, and very solid. It creates an Office 97 .xls file that you can open in current versions Excel or OpenOffice. I use Office 2007 with a variety of different .xls and .xlsx formats people send me, and it's completely transparent; thus you shouldn't need to worry about that.

    From the docs, it looks like it can insert charts, with control over the type of chart, data rows and columns, chart and axis titles, etc. It should do what you need. Try some of the examples.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found