Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datawindow save to Excel or Word 1

Status
Not open for further replies.

girls3dog1

Programmer
Nov 22, 2002
30
US
How can I save a datawindow report to either Excel or Word?
 
If you use the datawindow saveas() function to save the datawindow as an Excel file, it will only save the data, none of the formatting, or grouping. You can use saveas() to save the data in a psr file, that is a Power Soft Report. A psr file contains the data and the formatting. To display a psr just set the dataobject of a datawindow to the psr file name. But be careful, any datawindow expressions will be re-evaluated when the file is displayed. For example if the datawindow has the date in a computed object using the now() function. It will display the current date at the time that the psr is displayed.

I prefer to do as much of the grouping and sorting as possible in the sql. Then if the result set is exported to an Excel file the data will be almost the same as what the datawindow displays, and it will be understandable to the user.
 

an Example...


OLEObject lobjExcel
lobjExcel = CREATE OLEObject
li_resultado = lobjExcel.ConnectToNewObject( "excel.application")
if li_resultado <> 0 then goto fallo

lobjExcel.WorkBooks.Add

lobjExcel.Columns(&quot;E:E&quot;).ColumnWidth = 15
lobjExcel.Columns(&quot;F:F&quot;).ColumnWidth = 30
lobjExcel.Columns(&quot;G:G&quot;).ColumnWidth = 14

lds_control = create datastore
lds_control.dataobject = &quot;ds_ba_autorizacion_de_pago&quot;
lds_control.settransobject(sqlca)

lds_detalle = create datastore
lds_detalle .dataobject = &quot;ds_ba_autorizacion_de_pago_det&quot;
lds_detalle .settransobject(sqlca)

ll_total = lds_control.retrieve(as_empresa, as_ente)
for i = 1 to ll_total
ls_ente = lds_control.getitemstring(i, &quot;cod_ente&quot;)
lobjExcel.Activesheet.Cells(ll_fila, 2).Value = lds_control.getitemstring(i, &quot;nom_cliente&quot;)

ll_totdet = lds_detalle.retrieve(as_empresa, ls_ente, gnvuo_sesion.event eu_obtener_oficina(), gnvuo_sesion.event eu_obtener_usuario(), &quot;9&quot;, adt_inicio, adt_final )
for j = 1 to ll_totdet
ll_fila ++
if j <> 1 then
ls_monant = ls_moneda
end if
ls_moneda = lds_detalle.getitemstring(j , &quot;des_moneda&quot;)

if ls_moneda <> ls_monant then
lobjExcel.Activesheet.Cells(ll_fila, 3).Value = &quot;Moneda&quot;
lobjExcel.Activesheet.Cells(ll_fila, 4).Value = ls_moneda
ll_fila ++
lobjExcel.Activesheet.Cells(ll_fila, 3).Value = &quot;Cuenta&quot;
lobjExcel.Activesheet.Cells(ll_fila, 4).Value = &quot;No Cheque&quot;
lobjExcel.Activesheet.Cells(ll_fila, 5).Value = &quot;Fec.Impresión&quot;
lobjExcel.Activesheet.Cells(ll_fila, 6).Value = &quot;Beneficiario&quot;
lobjExcel.Activesheet.Cells(ll_fila, 7).Value = &quot;Mto Cheque&quot;
//lobjExcel.Activesheet.Cells(ll_fila, 7).Style = &quot;Currency&quot;
//lobjExcel.Activesheet.Cells(ll_fila, 7).NumberFormat = &quot;#,##0.00&quot;

lobjExcel.Activesheet.Range(&quot;C&quot; + string(ll_fila) + &quot;:G&quot; + string(ll_fila)).Font.Bold = true
ll_fila ++
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top