Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Formatting cells in Excel

by davies (Vicar)
on Feb 02, 2010 at 23:47 UTC ( #821058=note: print w/ replies, xml ) Need Help??


in reply to Formatting cells in Excel

Surprisingly, it's not totally clear what you want. Do you want "0200" as a string (which is what you say) or the number 200 formatted with a leading zero (which is what you seem to be trying to do)? The following code illustrates both:

use strict; use warnings; use diagnostics; use Win32::OLE; my $xl = Win32::OLE->new('Excel.Application'); $xl->{Visible} = 1; $xl->Workbooks->Add; my $rng = $xl->Workbooks(1)->Sheets(1)->Range("A1"); $rng->{Value} = 200; $rng->{NumberFormat} = "0000"; $rng = $xl->Workbooks(1)->Sheets(1)->Range("A2"); $rng->{Value} = "'0200";
A1 contains the number formatted with a leading zero (you may need some variant on this depending on what you are doing). A2 contains the text string. Note on the last line that the assignment starts with a double quote followed by a single quote. The text string doesn't (usually) need formatting.

Hope this helps and regards,

John Davies


Comment on Re: Formatting cells in Excel
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2015-07-28 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (256 votes), past polls