By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,276 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,276 IT Pros & Developers. It's quick & easy.

How do i transfer data to an excel sheet?

100+
P: 170
hi to all,

i'm having problems with a perl programe, i'm very new to it.
currently my script output data to a excel file, however i need to group the datas into boxes, pls help
Jan 23 '08 #1
Share this Question
Share on Google+
8 Replies


nithinpes
Expert 100+
P: 410
hi to all,

i'm having problems with a perl programe, i'm very new to it.
currently my script output data to a excel file, however i need to group the datas into boxes, pls help

Go through DBD::Excel and Spreadsheet::WriteExcel modules in CPAN. They may be of help.
Jan 23 '08 #2

100+
P: 170
hm...so i have to install the spreadsheet::excel module right? if not it won't work

here's my program not sure if it will help u to see the problem


Expand|Select|Wrap|Line Numbers
  1. #####    START OF MAIN PROGRAM    #####
  2. #####    LIST OF PARAMETERS    #####
  3.  
  4.  
  5.     @parameters = qw/MO /;
  6.  
  7.             # Please add in the neccessary fields here!!!
  8.                                         # Field name is case-sensitive!!!
  9.  
  10.  
  11.  
  12.  
  13. #####    WELCOME MESSAGE    ####
  14.  
  15.     print "\nWelcome to SMSC STATISTICS!\n";                    
  16.  
  17. #####    REQUEST NAME OF SMSC USED    #####
  18.  
  19.     print "\nPlease enter the name of the SMSC used (1, 2 , 3, 4 or 5):\n";
  20.     $smsc_name = <STDIN>;
  21.     $smsc_name = $smsc_name * 1;
  22.  
  23.     if ($smsc_name == "1")
  24.     { $max_pk_msg = 140;}
  25.  
  26.     if ($smsc_name == "2")
  27.     {$max_pk_msg = 40;}
  28.  
  29.     if ($smsc_name == "3")
  30.     {$max_pk_msg = 100;}
  31.  
  32.     if ($smsc_name == "4")
  33.     {$max_pk_msg = 80;}
  34.  
  35.     if ($smsc_name == "5")
  36.     {$max_pk_msg = 100;}
  37.  
  38. #####    REQUEST NAME OF FILE USED        #####
  39.  
  40.     print "\nPlease enter the date used to compute the statistics <yymmdd : e.g. 020222>:\n";
  41.     $file_name = <STDIN>;
  42.     $rev_file_name = scalar reverse $file_name;
  43.     $file_name = scalar reverse substr($rev_file_name,1);
  44.     $file_name1 = "DR"."$file_name".".PRT";
  45.     open (FILE1,"$file_name1") || die "Couldn't OPEN $file_name!!!\n\n";  
  46.  
  47. #####    REQUEST NAME OF ADDITIONAL FIELDS    #####
  48.  
  49.     $a = 0;
  50.  
  51.     do
  52.     {
  53.     print "\nPlease enter the name of the additional field to be computed (Case-Sensitive!)\n";
  54.     print "(Press 1 to exit!):\n";
  55.     $add_field = <STDIN>;
  56.     $rev_add_field = scalar reverse $add_field;
  57.     $add_field = scalar reverse substr($rev_add_field,1);
  58.  
  59.         if ($add_field == "1")
  60.         {
  61.         $a = 1;
  62.         }
  63.  
  64.         if ($add_field != "1")
  65.         {
  66.         push @parameters, "$add_field";
  67.         }
  68.  
  69.     }while ($a < 1);
  70.  
  71.  
  72. #####    OPENING OF FILE    #####
  73.  
  74.     undef $/;
  75.     open (FILE1,"$file_name1") || die "Couldn't OPEN $file_name!!!\n";      
  76.     $_ = <FILE1>;
  77.     $original = $_;                                              
  78.     close(FILE1) || die "Couldn't CLOSE $file_name properly!!!\n";                    
  79.  
  80.     push @output, "Date,Total (IN),Succ (IN),Pk (IN)/Hrs,Pk (OUT)/Hrs,Peak Hour,Total (OUT),Succ (OUT),";
  81.  
  82.     foreach(@parameters)
  83.     {
  84.     push @output, "$_ (In),$_ (Out),";
  85.     }
  86.  
  87.     push @output, "Pk Msg/sec,Max Pk Msg/sec\n";
  88.  
  89. #####    OBTAINING DATE    #####
  90.  
  91.     $length_date = index($original,"From (local)");                
  92.     $date_line = substr($original,($length_date + 14));
  93.     $rev_date = scalar reverse $date_line;                
  94.     $date = scalar reverse substr($rev_date,-8);
  95.  
  96.     $day = scalar reverse substr($rev_date,-2);
  97.  
  98.     $date1 = scalar reverse $rev_date;
  99.     $date2 = substr($date1,3);
  100.     $rev_month = scalar reverse $date2;    
  101.     $month = scalar reverse substr($rev_month,-2);
  102.  
  103.     $save_file_name= "smsc"."$smsc_name"."_"."$month"."$day".".xls";
  104.  
  105. #####    OBTAINING SUCC IN    #####
  106.  
  107.     $length_succ_in = index($original,"SUBMIT successful");    
  108.     $succ_in_line = substr($original,($length_succ_in + 19));
  109.  
  110.     $length_succ_in1 = index($succ_in_line,"\n");    
  111.     print "SUCC LENGTH=$length_succ_in1\n";
  112.     $rev_succ_in = scalar reverse $succ_in_line;                
  113.     $succ_in = scalar reverse substr($rev_succ_in,-$length_succ_in1);
  114.  
  115.  
  116. #####    OBTAINING TOTAL IN    #####
  117.  
  118.     $length_total_in = index($succ_in_line,"Total");
  119.     $total_in_line = substr($succ_in_line,($length_total_in + 7));
  120.  
  121.     $length_total_in1 = index($total_in_line,"\n");    
  122.     $rev_total_in = scalar reverse $total_in_line;                
  123.     $total_in = scalar reverse substr($rev_total_in,-$length_total_in1);
  124.  
  125.  
  126.  
  127. #####    OBTAINING SUCC OUT (Part 1)    #####
  128.  
  129.     $length_succ_out_p1 = index($succ_in_line,"DELIVER successful");    
  130.     $succ_out_line_p1 = substr($succ_in_line,($length_succ_out_p1 + 20));
  131.  
  132.     $length_succ_out_p11 = index($succ_out_line_p1,"\n");    
  133.     $rev_succ_out_p1 = scalar reverse $succ_out_line_p1;                
  134.     $succ_out_p1 = scalar reverse substr($rev_succ_out_p1,-$length_succ_out_p11);
  135.  
  136. #####    OBTAINING TOTAL OUT (Part 1)    #####
  137.  
  138.     $length_total_out_p1 = index($succ_out_line_p1,"Total");    
  139.     $total_out_line_p1 = substr($succ_out_line_p1,($length_total_out_p1 + 7));
  140.  
  141.     $length_total_out_p11 = index($total_out_line,"\n");    
  142.     $rev_total_out_p1 = scalar reverse $total_out_line_p1;                
  143.     $total_out_p1 = scalar reverse substr($rev_total_out_p1,-$length_total_out_p11);
  144.  
  145. #####    OBTAINING SUCC OUT (Part 2)    #####
  146.  
  147.     $length_succ_out_p2 = index($total_out_line_p1,"Status rep. deliv. successful");    
  148.     $succ_out_line_p2 = substr($total_out_line_p1,($length_succ_out_p2 + 31));
  149.  
  150.     $length_succ_out_p21 = index($succ_out_line_p2,"\n");    
  151.     $rev_succ_out_p2 = scalar reverse $succ_out_line_p2;                
  152.     $succ_out_p2 = scalar reverse substr($rev_succ_out_p2,-$length_succ_out_p21);
  153.  
  154. #####    OBTAINING TOTAL OUT (Part 2)    #####
  155.  
  156.     $length_total_out_p2 = index($succ_out_line_p2,"Total");    
  157.     $total_out_line_p2 = substr($succ_out_line_p2,($length_total_out_p2 + 7));
  158.  
  159.     $length_total_out_p21 = index($total_out_line,"\n");    
  160.     $rev_total_out_p2 = scalar reverse $total_out_line_p2;                
  161.     $total_out_p2 = scalar reverse substr($rev_total_out_p2,-$length_total_out_p21);
  162.  
  163. #####    OBTAINING SUCC OUT (Part 3)    #####
  164.  
  165.     $length_succ_out_p3 = index($total_out_line_p2,"Status rep. deliv. successful");    
  166.     $succ_out_line_p3 = substr($total_out_line_p2,($length_succ_out_p3 + 31));
  167.  
  168.     $length_succ_out_p31 = index($succ_out_line_p3,"\n");    
  169.     $rev_succ_out_p3 = scalar reverse $succ_out_line_p3;                
  170.     $succ_out_p3 = scalar reverse substr($rev_succ_out_p3,-$length_succ_out_p31);
  171.  
  172. #####    OBTAINING TOTAL OUT (Part 3)    #####
  173.  
  174.     $length_total_out_p3 = index($succ_out_line_p3,"Total");    
  175.     $total_out_line_p3 = substr($succ_out_line_p3,($length_total_out_p3 + 7));
  176.  
  177.     $length_total_out_p31 = index($total_out_line,"\n");    
  178.     $rev_total_out_p3 = scalar reverse $total_out_line_p3;                
  179.     $total_out_p3 = scalar reverse substr($rev_total_out_p3,-$length_total_out_p31);
  180.  
  181. #####    OBTAINING SUCC OUT     #####    
  182.  
  183.     $succ_out = $succ_out_p1 + $succ_out_p2 + $succ_out_p3;        
  184.  
  185. #####    OBTAINING TOTAL OUT     #####
  186.  
  187.     $total_out = $total_out_p1 + $total_out_p2 + $total_out_p3;
  188.  
  189.  
  190.  
  191. #####    OBTAINING SUBMIT PARAGRAPH    #####
  192.  
  193.     $length_submit = index($original,"Submissions by hour of day");    
  194.     $submit = substr($original,$length_submit);
  195.  
  196.     $length_submit1 = index($submit,"Successful deliveries by application and hour of day");
  197.     $rev_submit = scalar reverse $submit;                
  198.     $submit_para = scalar reverse substr($rev_submit,-$length_submit1);
  199.  
  200. #####    OBTAINING DELIVERY PARAGRAPH        #####
  201.  
  202.     $length_delivery = index($original,"Successful deliveries by application and hour of day");    
  203.     $delivery = substr($original,$length_delivery);
  204.  
  205.     $length_delivery1 = index($delivery,"Failed delivery attempts by application and hour of day");
  206.     $rev_delivery = scalar reverse $delivery;                
  207.     $delivery_para = scalar reverse substr($rev_delivery,-$length_delivery1);
  208.  
  209.  
  210. #####    OBTAINING VARIOUS IN PARAMETERS        #####
  211.  
  212.     $l = 0;
  213.  
  214.     foreach(@parameters)
  215.     {
  216.     $length = length($_);
  217.     $length_parameters = index($submit_para,$_);
  218.     $parameters_req_para = substr($submit_para,$length_parameters);
  219.     $rev_parameters = scalar reverse $submit_para;
  220.     $parameters_line = substr($rev_parameters,-($length_parameters + $length));
  221.  
  222.     $length_parameters1 = index($parameters_line,"\n");
  223.     $rev_parameters1 = scalar reverse $parameters_line;
  224.     $parameters_line1 = substr($rev_parameters1,-$length_parameters1);
  225.  
  226.     $length_parameters2 = index($parameters_line1,$_) + $length;
  227.  
  228.     $length_total = index($parameters_req_para,"          Total ");
  229.     $total_line = substr($parameters_req_para,$length_total);
  230.  
  231.     $rev_total = scalar reverse $total_line; 
  232.     $total_line1 = scalar reverse substr($rev_total,-$length_parameters2);
  233.  
  234.     $parameter_in_value[$l] = substr($total_line1,-10);
  235.  
  236.     $parameter_in_array{$_} = $parameter_in_value[$l];
  237.  
  238.     $l++;
  239.     }
  240.  
  241. #####    OBTAINING VARIOUS OUT PARAMETERS    #####
  242.  
  243.     $l = 0;
  244.  
  245.     foreach(@parameters)
  246.     {
  247.     $length = length($_);
  248.     $length_parameters = index($delivery_para,$_);
  249.     $parameters_req_para = substr($delivery_para,$length_parameters);
  250.     $rev_parameters = scalar reverse $delivery_para;
  251.     $parameters_line = substr($rev_parameters,-($length_parameters + $length));
  252.  
  253.     $length_parameters1 = index($parameters_line,"\n");
  254.     $rev_parameters1 = scalar reverse $parameters_line;
  255.     $parameters_line1 = substr($rev_parameters1,-$length_parameters1);
  256.  
  257.     $length_parameters2 = index($parameters_line1,$_) + $length;
  258.  
  259.     $length_total = index($parameters_req_para,"          Total ");
  260.     $total_line = substr($parameters_req_para,$length_total);
  261.  
  262.     $rev_total = scalar reverse $total_line; 
  263.     $total_line1 = scalar reverse substr($rev_total,-$length_parameters2);
  264.  
  265.     $parameter_out_value[$l] = substr($total_line1,-10);
  266.  
  267.     $parameter_out_array{$_} = $parameter_out_value[$l];
  268.  
  269.     $l++;
  270.     }
  271.  
  272. #####     TESTING
  273.  
  274. #####    OBTAINING PEAK IN Traffics            #####
  275.  
  276.     print "Obtaining Peak AO\n";
  277.     $length_pk_in = index($submit_para,"MO        AO   MO Flex   AO Flex     Total");    
  278. #    $length_pk_in = index($submit_para,"Submissions by hour of day");    
  279.     $pk_in_line = substr($submit_para,$length_pk_in);
  280.  
  281.     @hours = qw/00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23/;
  282.  
  283.     $l = 0;
  284.  
  285.         foreach (@hours)
  286.         {
  287.         $length_pk_in = index($pk_in_line,"$_ ");
  288.  
  289.         $pk_in_line = substr($pk_in_line,($length_pk_in + 2));
  290.  
  291.         $length_pk_in1 = index($pk_in_line,"\n");
  292.         $rev_pk_in = scalar reverse $pk_in_line;                
  293.         $apps_hours_in[$l] = scalar reverse substr($rev_pk_in,-$length_pk_in1);
  294.         $apps_hours_in[$l] = substr($apps_hours_in[$l],44);
  295.         $in_apps_hours{$apps_hours_in[$l]} = $_;
  296.  
  297.         print "apps_hours_in[$l] as $apps_hours_in[$l]\n";
  298.         $l++;
  299.         }
  300.  
  301.     sub numerically { $b <=> $a; }
  302.  
  303.     @pk_in_apps = sort numerically @apps_hours_in;
  304.  
  305.     $pk_in = $pk_in_apps[0];
  306.     $pk_hour = $in_apps_hours{$pk_in_apps[0]} * 100;
  307.     $pk_hour_dur = $pk_hour + 100;
  308.  
  309.         if ($pk_hour_dur == "2400") 
  310.         { 
  311.         $pk_hour_dur = "0000";
  312.         }
  313.     print "Peak IN (MO+AO) in as $pk_in at $pk_hour.\n";
  314. ########################
  315.  
  316.  
  317.  
  318. #####    OBTAINING PEAK OUT            #####
  319.  
  320.     $length_pk_out = index($delivery_para,"All applications");    
  321.     $pk_out_line = substr($delivery_para,$length_pk_out);
  322.  
  323.     @hours = qw/00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23/;
  324.  
  325.     $l = 0;
  326.  
  327.         foreach (@hours)
  328.         {
  329.         $length_pk_out = index($pk_out_line,"$_ ");
  330.         $pk_out_line = substr($pk_out_line,($length_pk_out + 2));
  331.  
  332.         $length_pk_out1 = index($pk_out_line,"\n");
  333.         $rev_pk_out = scalar reverse $pk_out_line;                
  334.         $apps_hours_out[$l] = scalar reverse substr($rev_pk_out,-$length_pk_out1);
  335.         $l++;
  336.         }
  337.  
  338.     sub numerically { $b <=> $a; }
  339.  
  340.     @pk_out_apps = sort numerically @apps_hours_out;
  341.     $pk_out = $pk_out_apps[0];
  342.  
  343.  
  344.  
  345. #####    OBTAINING PEAK MESSAGE/SEC        #####
  346.  
  347.     $pk_msg = $pk_in_apps[0] / 3600;
  348.  
  349. #####    PRINTING RESULT TO FILE            #####
  350.  
  351.     open (OUTPUT,">$save_file_name") || die "Couldn't OPEN $save_file_name!!!\n"; 
  352.  
  353.     push @output, "$date,$total_in,$succ_in,$pk_in,$pk_out,$pk_hour - $pk_hour_dur hr,$total_out,$succ_out,";
  354.  
  355.     foreach(@parameters)
  356.     {
  357.     push @output, "$parameter_in_array{$_},$parameter_out_array{$_},";
  358.     }
  359.  
  360.  
  361.     print OUTPUT @output;
  362.     printf (OUTPUT "%.2f,$max_pk_msg\n",$pk_msg);
  363.  
  364.     close(OUTPUT) || die "Couldn't CLOSE $save_file_name properly!!!\n";                
  365.  
  366.     print "\nPlease remember to collect your file at $save_file_name!\n";
  367.     print "\nThank you for using STARHUB SMSC STATISTICS!\n\n";         
  368.  
  369. #####    END OF PROGRAM                #####
  370.  
Basically, the output is to an excel file....think i just need to modify the last part, yeah
thanks



;
Jan 24 '08 #3

100+
P: 170
sorrie for the long post
but i pretty much figured out how to export to excel using win32::OLE
cos using Spreadsheet:Excel i have to install extra modules in

but now if i need to append data into my program using win32::OLE, is it possible?
pls advise guys, thanks
Jan 24 '08 #4

nithinpes
Expert 100+
P: 410
If your objective is to type the data into separate cells and format the output into columns and rows, keep in mind the action of following escape sequences in Excel sheet:

\t - will move to next adjacent cell(in the same row)
\n - will move to next line ( to next row)

In the this line of your code,
Expand|Select|Wrap|Line Numbers
  1. push @output, "$date,$total_in,$succ_in,$pk_in,$pk_out,$pk_hour -$pk_hour_dur hr,$total_out,$succ_out,";
  2.  
you are pushing the variables as a single comma separated string. If you want them to be separate elements inorder to print them in separate columns, modify it as below:

Expand|Select|Wrap|Line Numbers
  1. push @output, ($date,$total_in,$succ_in,$pk_in,$pk_out,$pk_hour -$pk_hour_dur hr,$total_out,$succ_out);
  2.  
To print the contents use:
Expand|Select|Wrap|Line Numbers
  1. print "$_\t" foreach(@output);   
  2. ### instead of: print OUTPUT @output;
  3.  print "\n" ; ## will move to next row
  4.  
Apart from this, if you want to do advanced level of formatting like printing particular data into a specific cell, you have to use Spreadsheet::WriteExcel.

Note: If you want to pass all records in an array, you have to create a two-dimensional array. Each element in the array being a list of data to be printed in each row.
Jan 24 '08 #5

100+
P: 170
ok i've actually done it in another way where particular values are assigned to specified cells using win32::OLE
here's what i've done:

Expand|Select|Wrap|Line Numbers
  1. use Win32::OLE;
  2.  
  3.         # use existing instance if Excel is already running
  4.         eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
  5.         die "Excel not installed" if $@;
  6.         unless (defined $ex) {
  7.             $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
  8.                     or die "Oops, cannot start Excel";
  9.         }
  10.  
  11.  
  12.         # get a new workbook
  13.         $book = $ex->Workbooks->Add;
  14.     $sheet = $book->Worksheets(1);
  15.  
  16.         # write a 2 rows by 3 columns range
  17.         $sheet->Range("A1:J2")->{Value} = [['Date','Total (IN)','Succ (IN)','Pk (IN)/Hrs','Pk (OUT)/Hrs','Peak Hour','Total (OUT)','Succ (OUT)','MO(IN)','MO(OUT)'],
  18.                                            [$date, $total_in, $succ_in,$pk_in,$pk_out,"$pk_hour - $pk_hour_dur hr",$total_out,$succ_out ]];
  19.  
  20.     $sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
  21.                       [$max_pk_msg,$pk_msg]];
  22.  
  23.     $sheet->Cells(3,10)->{Value} = [$save_file_name];
  24.     foreach(@parameters)
  25.     {
  26.     $sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
  27.     $sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
  28.     }
  29.  
  30.         # print "XyzzyPerl"
  31.         $array = $sheet->Range("A2:I1")->{Value};
  32.         for (@$array) {
  33.             for (@$_) {
  34.                 print defined($_) ? "$_|" : "<undef>|";
  35.             }
  36.             print "\n";
  37.         }
  38.  
  39.         # save and exit
  40.  
  41.          $book->SaveAs ('C:\Documents and Settings\clong\Desktop\perl\$save_file_name.xls') ;
  42.         undef $book;
  43.         undef $ex;
  44.  
now any idea if say i wanna save $save_file_name as i've declared earlier?
cos they just save it as $save_file_name
however i declared $save_file_name as smsc_0101 in my earlier program
advise pls?

thanks
Jan 25 '08 #6

nithinpes
Expert 100+
P: 410
ok i've actually done it in another way where particular values are assigned to specified cells using win32::OLE
here's what i've done:

Expand|Select|Wrap|Line Numbers
  1. use Win32::OLE;
  2.  
  3.         # use existing instance if Excel is already running
  4.         eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
  5.         die "Excel not installed" if $@;
  6.         unless (defined $ex) {
  7.             $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
  8.                     or die "Oops, cannot start Excel";
  9.         }
  10.  
  11.  
  12.         # get a new workbook
  13.         $book = $ex->Workbooks->Add;
  14.     $sheet = $book->Worksheets(1);
  15.  
  16.         # write a 2 rows by 3 columns range
  17.         $sheet->Range("A1:J2")->{Value} = [['Date','Total (IN)','Succ (IN)','Pk (IN)/Hrs','Pk (OUT)/Hrs','Peak Hour','Total (OUT)','Succ (OUT)','MO(IN)','MO(OUT)'],
  18.                                            [$date, $total_in, $succ_in,$pk_in,$pk_out,"$pk_hour - $pk_hour_dur hr",$total_out,$succ_out ]];
  19.  
  20.     $sheet->Range("K1:L2")->{Value} = [['Pk Msg/sec','Max Pk Msg/sec'],
  21.                       [$max_pk_msg,$pk_msg]];
  22.  
  23.     $sheet->Cells(3,10)->{Value} = [$save_file_name];
  24.     foreach(@parameters)
  25.     {
  26.     $sheet->Cells(2,9)->{Value} = [$parameter_in_array{$_}];
  27.     $sheet->Cells(2,10)->{Value} = [$parameter_out_array{$_}];
  28.     }
  29.  
  30.         # print "XyzzyPerl"
  31.         $array = $sheet->Range("A2:I1")->{Value};
  32.         for (@$array) {
  33.             for (@$_) {
  34.                 print defined($_) ? "$_|" : "<undef>|";
  35.             }
  36.             print "\n";
  37.         }
  38.  
  39.         # save and exit
  40.  
  41.          $book->SaveAs ('C:\Documents and Settings\clong\Desktop\perl\$save_file_name.xls') ;
  42.         undef $book;
  43.         undef $ex;
  44.  
now any idea if say i wanna save $save_file_name as i've declared earlier?
cos they just save it as $save_file_name
however i declared $save_file_name as smsc_0101 in my earlier program
advise pls?

thanks
Assign the value of $save_file_name as in your previous script.
Change this line in your code:
Expand|Select|Wrap|Line Numbers
  1.    $book->SaveAs ('C:\Documents and Settings\clong\Desktop\perl\$save_file_name.xls') ;
  2.  
to :
Expand|Select|Wrap|Line Numbers
  1.    $book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
  2.  
If you use single quotes, the string inside it will be taken as literal string. There won't be any substitutions.
Use double quotes for substiotution and escape the backslashes so that they are taken as actual backslash (to avoid misinterpretation with escape sequences).
Jan 25 '08 #7

nithinpes
Expert 100+
P: 410
Assign the value of $save_file_name as in your previous script.
Change this line in your code:
Expand|Select|Wrap|Line Numbers
  1.    $book->SaveAs ('C:\Documents and Settings\clong\Desktop\perl\$save_file_name.xls') ;
  2.  
to :
Expand|Select|Wrap|Line Numbers
  1.    $book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xls") ;
  2.  
If you use single quotes, the string inside it will be taken as literal string. There won't be any substitutions.
Use double quotes for substiotution and escape the backslashes so that they are taken as actual backslash (to avoid misinterpretation with escape sequences).
Jan 25 '08 #8

100+
P: 170
thank you very much!

it work! right i need to know how to append my info now...any problems i will get back again..thanks once again
Jan 25 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.