F_COPY_DATASTORE_TO_EXCEL

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name : f_copy_datastore_to_excel
// Argument Name : apo_dwo, Arg Type : PowerObject, Pass By : Value
// Return Type :      Integer
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

datawindow ldw_control
datastore lds_control
integer li_i
OleObject obj_excel_appl
OleObject obj_excel_workbook

If apo_dwo.typeof() = datawindow! Then
    ldw_control = apo_dwo
    li_i = ldw_control.saveas('', Clipboard!, True)
ElseIf apo_dwo.typeof() = datastore! Then
    lds_control = apo_dwo
    li_i = lds_control.saveas('', Clipboard!, True)
Else
    MessageBox('Error', 'Invalid Object.', Exclamation!)
    li_i = -1
End If

If li_i = 1 Then
    obj_excel_appl = Create OleObject
    If obj_excel_appl.ConnectToObject('', 'excel.application') = 0 Then
        obj_excel_workbook = obj_excel_appl.Workbooks.Add()
        obj_excel_appl.ActiveSheet.Paste()
        MessageBox('Done', 'Data is copied to workbook "' + &
                                string(obj_excel_workbook.name) + &
                                '"', information!)
    Else
        MessageBox('Error', 'Ms Excel is not running.', Exclamation!)
        li_i = -1
    End If
    Destroy obj_excel_appl
End If

Return li_i

0 comments:

Post a Comment