Thank you for the comments and help which stopped m looking in crypts that would have nothing in them!
I have done more work and to help I used the sub below.
I believe that I have found that the problem was caused by having a directory
that contained ‘[]’ characters since when I removed these all was well.
It would interesting to know if these characters are not ‘preferred’ in some sense.
To confuse matters, I have a suspicion that this will not be found on all PCs under windows but I cannot be sure
sub copy_edit_savesp_test($$$) {
my ($file_name, $dir_in, $dir_out) = @_;
my ($file_name_in_full, $file_name_out_full, $excel, $excel_res, $work
+book, $copy_res);
my ($add_data_sp, $row, $workbook_res, $ew_message, $wksht, $wksht_str
+, $worksheet);
$file_name_in_full = $dir_in . '\\' . $file_name;
$file_name_out_full = $dir_out . '\\' . $file_name;
$copy_res = copy($file_name_in_full, $file_name_out_full);
print "\ndir file <$file_name>\nin <$dir_in>\n$dir_out\n";
print "\n[copy_edit_savesp_test] copy res <$copy_res> for <$file_name_
+out_full>\n";
$excel_res = 1;
$excel = Win32::OLE->new('Excel.Application', 'Quit') or ($excel_res =
+ 0, $ew_message = "Could not create excel object");
print "[copy_edit_savesp_test] open res <$excel_res> excel <$excel> wo
+rkbook <$workbook>\n";
if($excel_res == 1) {
$workbook_res = 1;
$ew_message = "work book ok";
$workbook = $excel->Workbooks->Open($file_name_out_full) or ($wor
+kbook_res = 0, $ew_message = "Could not open excel workbook");
print "[copy_edit_savesp_test] after workbook result <$workbook_re
+s> message <$ew_message>\n";
$add_data_sp = 'yes';
if($add_data_sp eq 'yes') {
$wksht +=1;
$wksht_str = "sheet" . $wksht;
$worksheet = $excel->ActiveWorkbook->Worksheets($wksht_str);
$row = 2;
$worksheet->Cells($row,9)->{Value} = "row $row 9";
$row = 3;
$worksheet->Cells($row,6)->{Value} = "row $row 6";
$worksheet->Cells($row,8)->{Value} = "row $row 8";
} else {
print "\n[copy_edit_savesp_test]no data added to spredsheet\n"
+;
}
}
$excel->{DisplayAlerts}=0;
$ew_message = "just before saving spreadsheet";
print "before message <$ew_message>\n";
$excel_res = 1;
$excel->Workbooks(1)->SaveAs($file_name_out_full) or ($excel_res = 0,
+ $ew_message = "Could not save spreadsheet>");
print "[copy_edit_savesp_test] after saving spredsheet result <$excel_
+res> message <$ew_message>\n\n";
$excel->{DisplayAlerts}=1;
}
|