You can probably accomplish what you want by doing [Format][Cell][Number tab] and selecting "text". Excel likes to infer that cells are dates because then it can treat them as an ordered list, and you can do arithmetic like "this day next week = today + 7". Under [Format][Cell][Number tab] the date selection has a number of good options for date presentation, but none seem to meet your needs.

Glen Plantz wrote:

Hi Folks,
I'm having trouble formatting the Cell Contents of an Excel sheet with Win32::OLE. I want to force the contents of a Cell that has a DATE value ( "Dec 2005" ) to be a string.
What happens is the Date value 'DEC 2005' in converted into 'Dec-05'.
Any help will be greatly appreciated.... Thanks,

Glen Plantz
Here is my code;.
---------------------------------------------------------------------------------------------------------------------------------------------------
my ($currentMonth, $currentYear ) = split / /, $currentMonthYear; # holds "Dec 2005" # Now open the TEMPLATE FILE where this month value will be used...
# $CSAA_A2_RegionOffice

my $template_Workbook = $excel_app->Workbooks->Open($CSAA_A2_RegionOffice)
or die "could not open $CSAA_A2_RegionOffice\n";
#now select first column heading where HOA will be used... and try putting the correct column heading in...
my $Sheet1 = $template_Workbook->Worksheets(1);
$Sheet1->Range("D2")->Select();

#now select correct array based on the '$currentMonth' value
my $mnth;
my $i = 0;
my $mnth = $HOA{$currentMonth}[$i]; # $mnth holds 'DEC' #correct value... now try putting in the correct value... my $monthYear = $mnth . ' ' . $currentYear; print "monthYear = $monthYear\n"; # my $dt = Variant(VT_DATE, $monthYear);
print "$dt\n";
print $dt->Date("MMM yyyy"), "\n";
my $formatedDate = $dt->Date("MMM yyyy"), "\n";
print "formatedDate = $formatedDate\n";
# this works, but the year has the format '05'.... see screen shot...
$Sheet1->Range("D2")->{'Value'} = $monthYear;
# this does not work
#$Sheet1->Range("D2")->{'Value'} = $formatedDate;
#this doesn't seem to effect the value entered...
#$Sheet1->Range("D2")->Format("MMM yyyy");
------------------------------------------------------------------------

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

--

R. Dennis Kelly


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to