我们的PowerBuilder应用程序通过打印DataWindow文件来生成报告。现在,我们想要修改PB,以便生成Excel而不是PDF。
在我的PB代码中,我尝试使用以下函数:
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注意: adw_datawindow是我想要打印的DataWindow;as_filename是输出文件名。但是,这似乎不起作用,因为我在打开文件时遇到错误。
你知道怎么做吗?我们的环境:
PB版本: PB 12 Classic;Excel版本: MS Excel 2007
发布于 2012-11-01 04:19:06
您的代码应该可以工作;您应该检查错误代码,因为它将包含有意义的信息。
可能是权限(文件)问题、文件争用问题、错误文件夹(无效字符)等,也可能是锁定的现有文件。看看文件/文件夹是否首先存在也无伤大雅。您可以使用FileExists(as_filename)检查文件,也可以使用DirectoryExists(as_directory)检查文件夹。
你可以试试Excel8!用于Excel版本8或更高版本,但我认为您的Excel!应该可以很好地工作。
// Add saveastype as parameter to function
public function integer save_dw_to_file (datawindow adw_datawindow, &
string as_filename, &
string as_folder, &
SaveAsType sat_SaveType)
int li_rc
string ls_tmp_file
ls_tmp_file = as_filename
// add file extension based on saveastype
choose case sat_SaveType
case Excel!, Excel5!, Excel8!
ls_tmp_file += '_temp.xls'
case PDF!
ls_tmp_file += '_temp.pdf'
end choose
if FileExists ( ls_tmp_file ) Then
if MessageBox('File already exists','Would you like to replace: ' + &
ls_tmp_file + '?', Question!, YesNo!, 2) = 2 then
return -1
end if
end if
// save type based on parameter to function
li_rc = adw_datawindow.saveas(ls_tmp_file, sat_SaveType, true)
if li_rc = -1 then
MessageBox('Error saving file','Unable to save file: ' + ls_tmp_file)
end if
return li_rchttps://stackoverflow.com/questions/13118818
复制相似问题