Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Set Excel file name (without saving!)

by dangiles (Initiate)
on Aug 21, 2012 at 17:40 UTC ( #988805=perlquestion: print w/ replies, xml ) Need Help??
dangiles has asked for the wisdom of the Perl Monks concerning the following question:

I want to set the filename of an Excel (Win32::OLE, ActiveState Perl) workbook without saving it. (So I do not want to use $Book->SaveAs.) I tried a few variations of "$Book->{Name} = $name;" but none worked.

I want to create a workbook and let the user safe it, but give it a default file name.
Dan Giles, simple novice

Comment on Set Excel file name (without saving!)
Re: Set Excel file name (without saving!)
by Riales (Hermit) on Aug 21, 2012 at 17:46 UTC

    Do you mean...

    > cp OriginalFileName.xls DefaultFileName.xls

    ?

      Not quite. The workbook is created with $Excel->Workbooks->Add, so the original file name is 'Book1'. I want the user to save the spreadsheet themselves (if they want to), but give them a 'default' name of something better than Book1. So when they do a 'Save As' from Excel, the file is already named correctly; they just need to pick the folder they want to dump it in.

      If I can give the Add method a file name without it complaining that the file doesn't exist, that would work also!

      Dan Giles, simple novice

        Sorry, I was actually not familiar with the Win32::OLE module (at all), but I've taken a quick look-see and here's what I've gleaned...

        It sounds like you're trying to automate some part of creating a spreadsheet while a user is editing that same spreadsheet. To me, that sounds like a recipe for a mess, but I don't really know what it is you are ultimately trying to do. If it were me, I would have the script take in parameters up front and then have the script do everything instead of having both the user and the script working on some spreadsheet at once.

        So for your case, I would take the folder they want to dump the excel file in up front as a parameter to the script, and just go ahead and create the workbook in that folder. Now they have a saved workbook with the proper name in the proper folder.

        Hope that helps!

Re: Set Excel file name (without saving!)
by dasgar (Deacon) on Aug 21, 2012 at 18:45 UTC

    I'm not sure I'm understanding what it is that you are doing and what you're trying to do.

    An Excel workbook is essentially the Excel file itself. If you want to change the name of an existing Excel file, you can use built-in functions from your OS, such as cp and copy.

    If you're wanting to use Win32::OLE and Excel to either change the name of the file or create a new file and save it with a specific file name, the you'll have to use the "SaveAs" method that you say you're wanting to avoid.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-08-31 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls