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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|