怎么把当前数据窗口的数据导出为excel或word表格或txt文本

如何把当前数据窗口的数据导出为excel或word表格或txt文本?
我想实现把当前数据窗口的数据导出为excel或word表格或txt文本,请问这如何实现???
想了许多办法,老是不成功。。。
说明一点:数据窗口有多个,我想把当前处于激活状况的数据窗口的数据导出为excel或word表格或txt文本。

------解决方案--------------------
多个数据窗口切换,那应该用到tab控件的吗?
那可以在标签页切换事件中:
datawindow idw

choose case newindex 
case 1
idw = tab_1.tabpage_1.dw_1
idw.settransobject(sqlca)
idw.retrieve(参数)
//其他处理...
case 2
idw = tab_1.tabpage_2.dw_2
idw.settransobject(sqlca)
idw.retrieve(参数)
//其他处理...
case 3
//处理...
...
end choose
idw.saveas() //也可写参数,直接指定保存文件或excel等,不写的话,运行时会弹出另存对话框给用户选择
------解决方案--------------------
上边的办法都比较简单,这些办法,不能处理ddlb 子数据窗口的显示值等,也无法修正格式

建议用OLE处理,虽然可能转出慢,但是显示的结果要好的多。

String ls_File,ls_Title
OLEObject OLEExcel,WorkBooks
Pointer oldpointer
Int ExcelOK,i,j,li_Net
String ls_StartAddress,ls_EndAddress
String ls_Style,ls_Value,ls_DispValue
String ls_BHCol,ls_McCol

//0>判断

if idwo.RowCount() > 65536 Then
MessageBox("提示","该数据超过65536行,系统无法进行处理!")
Return -1
end if

//1>文件名
ls_File = sle_1.Text

//2>删除
if FileExists(ls_File) Then

if Not FileDelete ( ls_File ) Then
MessageBox("提示","删除文件失败!"+ls_File)
Return -1
end if

End if

//3>创建EXCEL

OLEExcel = CREATE OLEObject

ExcelOK = OLEExcel.ConnectToNewObject( "Excel.Application" )
if ExcelOK <> 0 Then
MessageBox("提示","无法创建EXCEL文件,请检查是否已安装OFFICE-EXCEL办公软件!")
Return -1
end if

hpb_1.MinPosition = 1
hpb_1.MaxPosition = idwo.RowCount()
hpb_1.Position = 1
hpb_1.SetStep = 1

hpb_1.Visible = True
st_1.Visible = True

oldpointer = SetPointer(HourGlass!)

WorkBooks = OLEExcel.Application.Workbooks.Add() 

//1>报表名称&格式(第一行)
if lower(idwo.Title) = 'none' or Trim(idwo.Title) = '' Then
ls_Title = '报表导出的EXCEL文件'
Else
ls_Title = idwo.Title
End if
WorkBooks.Sheets(1).Cells(1,1).value = ls_Title
WorkBooks.Sheets(1).Cells(1,1).Font.Bold = True
WorkBooks.Sheets(1).Cells(1,1).Font.Name = "宋体"
WorkBooks.Sheets(1).Cells(1,1).Font.Size = 18
WorkBooks.Sheets(1).Cells(1,1).Font.FontStyle = "常规"
WorkBooks.Sheets(1).Cells(1,1).borders.linestyle = 0
//
WorkBooks.Sheets(1).Cells(2,1).Value = '导出时间:'+String(ToDay(),'yyyy-mm-dd hh:mm:ss')
WorkBooks.Sheets(1).Cells(2,1).Font.Bold = True
WorkBooks.Sheets(1).Cells(2,1).Font.Name = "宋体"
WorkBooks.Sheets(1).Cells(2,1).Font.Size = 10
WorkBooks.Sheets(1).Cells(2,1).Font.FontStyle = "常规"
WorkBooks.Sheets(1).Cells(2,1).borders.linestyle = 0

//2>标题
For i = 1 to UpperBound(is_Text)
WorkBooks.Sheets(1).Cells(3,i).value = is_Text[i]
Next


st_1.text = "正在设置标题格式,请稍候......"

//3>标题格式
ls_StartAddress = wf_GetAddress(3,1)
ls_EndAddress = wf_GetAddress(3,UpperBound(is_Col))
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).Font.Bold = True
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).Font.Name = "宋体"
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).Font.Size = 10
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).Font.FontStyle = "常规"
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).borders.linestyle = 1

//4>数据格式
ls_StartAddress = wf_GetAddress(4,1)
ls_EndAddress = wf_GetAddress(4+idwo.RowCount(),UpperBound(is_Col))
WorkBooks.Sheets(1).Range(ls_StartAddress+":"+ls_EndAddress).Font.Bold = True