Our PowerBuilder application generates a report by printing a DataWindow as PDF file. Now we would like to modify the PB such that an Excel is generated instead of PDF.
In my PB code I tried using the following function:
public function integer save_dw_to_file (datawindow adw_datawindow, string as_filename, string as_folder);
string ls_tmp_file_xls
ls_tmp_file_xls = as_filename+'_temp.xls'
adw_datawindow.saveas(ls_tmp_file_xls,Excel!,true)
return 1
end function
Note: adw_datawindow is the DataWindow that I want to print; as_filename is the output filename.
However, this seems not work because I got an error when I open the file.
Do you know how to do this? Our environment:
PB Version: PB 12 Classic; Excel Version: MS Excel 2007
Your code should work; you should check the error code because it will have meaningful info.
It could be a permissions (file) issue, file contention issue, bad folder (invalid characters), etc., existing file that is locked. Wouldn’t hurt to see if the file/folder exists first. You can check for the file using FileExists(as_filename) or you can check a folder by DirectoryExists(as_directory).
You could try Excel8! for Excel version 8 or higher but I think your Excel! should work just fine.