2012-10-29 2 views
2

PowerBuilder 애플리케이션은 데이터 윈도우를 PDF 파일로 인쇄하여 보고서를 생성합니다. 이제 우리는 PDF 대신 Excel이 생성되도록 PB를 수정하려고합니다. 나는 다음과 같은 기능을 사용하여 시도 내 PB 코드에서PowerBuilder 12 데이터 윈도우를 엑셀로 저장

:

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 내가 인쇄 할 데이터 윈도우입니다; as_filename은 출력 파일 이름입니다. 그러나이 파일을 열 때 오류가있어서이 작동하지 않는 것 같습니다.

이 작업을 수행하는 방법을 알고 계십니까? 우리 환경 :

PB 버전 : PB 12 클래식; Excel 버전 : MS Excel 2007

+0

Excel 파일을 열 때 오류가 발생 했습니까? 그렇다면 오류가 단서를 제공합니까? IDE/DataWindow 페인터에서 성공적으로 저장할 수 있습니까? Excel 세대가 데이터 세트에서 작동하는 동안 프리젠 테이션 레이어에서 PDF 생성이 작동하므로 포맷팅, 값 변환 드롭, 사용자 정의 된 컬럼 제목 등을 얻지 못할 것입니다. – Terry

답변

2

코드가 작동해야합니다. 의미있는 정보를 가지므로 오류 코드를 확인해야합니다.

권한 (파일) 문제, 파일 경합 문제, 잘못된 폴더 (잘못된 문자) 등 잠긴 기존 파일 일 수 있습니다. 파일/폴더가 먼저 존재하는지 확인하는 것이 좋습니다. 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_rc 
관련 문제